12.10 Taylor series

12.12 Approximation of functions using Taylor polynomials

Example 1. We begin by looking at the Taylor polynomials for f(x) = e^x . Recall that

nth degree Taylor polynomial of e^x = Taylor(exp)(x,n) = sum(x^j/j!,j = 0 .. n) .

> Taylor(exp) := (x,n) -> sum(x^j/j!, j=0..n);

Taylor(exp) := proc (x, n) options operator, arrow;...

> Taylor(exp)(x,8);

1+x+1/2*x^2+1/6*x^3+1/24*x^4+1/120*x^5+1/720*x^6+1/...

> evalf(Taylor(exp)(1,8));

2.718278770

These Taylor polynomials are the partial sums of a series that converges to f(x) = e^x pretty quickly. To see this, look at the case x = 1 .

> printf(" n approximation true value\n");
for i from 1 to 10 by 1 do
printf("%3d %12.8f %12.8f\n",i,evalf(Taylor(exp)(1,i)),evalf(exp(1)));
end do;

  n     approximation    true value

  1     2.00000000       2.71828183

  2     2.50000000       2.71828183

  3     2.66666667       2.71828183

  4     2.70833333       2.71828183

  5     2.71666667       2.71828183

  6     2.71805556       2.71828183

  7     2.71825397       2.71828183

  8     2.71827877       2.71828183

  9     2.71828153       2.71828183

 10     2.71828180       2.71828183

Example 2. Next we look at the MacLaurin series of f(x) = sin(x) .

> Taylor(sin):= (x,n) -> sum((-1)^(k+1)*x^(2*k-1)/(2*k-1)!,k=1..(ceil(n/2)));

Taylor(sin) := proc (x, n) options operator, arrow;...

> Taylor(sin)(x,5);

x-1/6*x^3+1/120*x^5

We want to see how well the Taylor polynomials approximate sin(x) for different values of x.

> plot([sin(x),Taylor(sin)(x,1),Taylor(sin)(x,5)],x=-2*Pi..2*Pi,y=-2..2,color=[red,blue,green]);

[Maple Plot]

(Note. Thanks to Dana Williams for this file.)