12.10 Taylor series
12.12 Approximation of functions using Taylor polynomials
Example 1. We begin by looking at the Taylor polynomials for . Recall that
nth degree Taylor polynomial of = Taylor(exp)(x,n) = .
> Taylor(exp) := (x,n) -> sum(x^j/j!, j=0..n);
> Taylor(exp)(x,8);
> evalf(Taylor(exp)(1,8));
These Taylor polynomials are the partial sums of a series that converges to pretty quickly. To see this, look at the case .
>
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 .
> Taylor(sin):= (x,n) -> sum((-1)^(k+1)*x^(2*k-1)/(2*k-1)!,k=1..(ceil(n/2)));
> Taylor(sin)(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]);
(Note. Thanks to Dana Williams for this file.)