>   

lab9.mws --- Taylor Polynomials and Their Remainders

>    restart;
with( plots ):
with( Student[Calculus1] ):

Warning, the name changecoords has been redefined

>   

Auxiliary Procedures (execute, but do not change)

>    TaylorError := proc(f,center::name={name,numeric},order::name={name,nonnegint})
  local a, df, R, x, n;
  x := lhs(center);
  a := rhs(center);
  n := rhs(order);
  df := simplify(diff( f, x$(n+1) ));
  R := eval(df,x=c)*(x-a)^(n+1)/(n+1)!;
  return unapply(R,x)
end proc:

>   

Lab Overview

The purpose of this lab is to help you develop an understanding of Taylor polynomials. Recall that the Taylor polynomial of order n based at x = a  for a function f(x)  is

  P[n,a](x) = Sum(f^``(k)*``(a)*(x-a)^k/k!,k = 0 .. n)                                                                                                      
 
`` = f(a)+`f '`(a)*(x-a)+`f ''`(a)*(x-a)^2/2+`f '''`(a)*(x-a)^3/6  + ... + f^``(n)  ( a ) (x-a)^n/n!  

In class you have talked about the remainder term for Taylor polynomials. You should have memorized the formula

  R[n](x)  = f^(n+1) ( c ) (x-a)^(n+1)/(n+1)!  .

The purpose of this lab is to make some sense out of these definitions. The primary way this will be done is through the use of graphics. The TaylorApproximation  command will be used for almost everything that we need in this lab. This command will be used to compute Taylor polynomials and to produce plots (and animations) of Taylor polynomials. For the study of the remainder term, I have created the TaylorError  command.

The lab questions are either taken directly from the assigned homework or based on the assigned problems.

  Deadline for submitting a lab solution is midnight, Thursday, March 20, 2003.  

>   

Example 1 - # 36 (p. 486)

The Taylor polynomial of order n = 6  centered at a = 1  for

>    f1 := 1/(x-3):
f(x) = f1;

f(x) = 1/(x-3)

is found with theTaylorApproximation  command

>    P[6,1] := TaylorApproximation( f1, x=1, order=6 );

P[6,1] := -9/128*x^4+1/16*x^3+1/32*x^5-43/128-1/128*x^6-11/128*x^2-3/32*x

Notice that this result is not displayed in terms of powers of ( x-1 ). This is an unfortunate consequence of the simplifications built into Maple.

>   

To see how this polynomial is related to the original function on an interval, say [ -3, 3 ], use the above command with the plotting interval specified as -3..3  and the argument output=plot  added to the previous command:

>    TaylorApproximation( f1, x=1, order=6, -3..3, output=plot );

[Maple Plot]

>   

Notice how T[6,1]  does an excellent job of approximating the original function at and near x = 1  and the approximation becomes worse and worse the further x  moves from x = 1 .

In this exercise you are asked to look at the remainder term

>    R[6] := TaylorError( f1, x=1, order=6 );

R[6] := proc (x) options operator, arrow; -1/(c-3)^8*(x-1)^7 end proc

where c is a number between a = 1  and x . For x = .5  this simplifies to

>    R[6](0.5);

.78125e-2/(c-3)^8

where  0.5 < c  < 1. To determine the largest possible value of this remainder term, plot the (absolute value of the) remainder -- as a function of c  -- over the interval of possible values for c :

>    plot( abs(R[6](0.5)), c=0.5..1 );

[Maple Plot]

Two observations are immediately obvious from this:

  i) the remainder are small for all values of c  

 ii) the largest possible value of this remainder occurs when c = 1  

>    MaxError := eval( abs(R[6](0.5)), c=1 );

MaxError := .3051757812e-4

What this means is that

  abs(f(.5)-P[6,1](.5))  <= 0.000031

To verify this result, compute the "actual" error between the function and its Taylor polynomial at x  = 0.5

>    ActualError := eval( abs(f1-P[6,1]), x=0.5 );

ActualError := .2441401e-4

and note that this error is within the error bound that we found.

>    evalb( ActualError < MaxError );

true

>   

Example 2 - Estimating exp(1)  

This example presents the ideas needed to answer Lab Question 2 (#39, p. 486 of the text).

The Maclaurin polynomials for

>    f2 := exp(x):
f(x) = f2;

f(x) = exp(x)

of all orders up to

>    N := 5;

N := 5

are

>    for n from 0 to N do
  P[n,0] := TaylorApproximation( f2, x=0, order=n );
end do;

P[0,0] := 1

P[1,0] := x+1

P[2,0] := 1+x+1/2*x^2

P[3,0] := 1+x+1/2*x^2+1/6*x^3

P[4,0] := 1+x+1/2*x^2+1/6*x^3+1/24*x^4

P[5,0] := 1+x+1/2*x^2+1/6*x^3+1/24*x^4+1/120*x^5

Recall that the coefficient of x^n is f^n*``(0)/n! = exp(0)/n!  = 1/n! .

The numerical estimates these provide for an approximation to exp(1)  = exp(1) are

>    for n from 0 to N do
  eval( P[n,0], x=1. );
end do;

1

2.

2.500000000

2.666666667

2.708333334

2.716666667

To know how accurate these approximations are, the corresponding remainder terms are needed:

>    for n from 0 to N do
  R[n] := TaylorError( f2, x=0, order=n );
end do;

R[0] := proc (x) options operator, arrow; exp(c)*x end proc

R[1] := proc (x) options operator, arrow; 1/2*exp(c)*x^2 end proc

R[2] := proc (x) options operator, arrow; 1/6*exp(c)*x^3 end proc

R[3] := proc (x) options operator, arrow; 1/24*exp(c)*x^4 end proc

R[4] := proc (x) options operator, arrow; 1/120*exp(c)*x^5 end proc

R[5] := proc (x) options operator, arrow; 1/720*exp(c)*x^6 end proc

where each c  is a number between 0 and 1.

Now, since we are trying to estimate a numerical value of exp(1) , it is not fair to use values of exp(c)  in these estimates. It is known that 2 < exp(1)  < 3. This, combined with our knowledge that 0 < c  < 1 allow us to conclude that exp(c)  < 3^c  < 3. Using this, we obtain the following bounds when the Maclaurin polynomials are evaluated at x = 1 :

>    for n from 0 to N do
  RR[n] := subs( exp(c)=3, R[n](1.) );
end do;

RR[0] := 3.

RR[1] := 1.500000000

RR[2] := .5000000001

RR[3] := .1250000000

RR[4] := .2500000000e-1

RR[5] := .4166666667e-2

What this tells, in particular, is that the Maclaurin polynomial of order 4 can be used to estimate exp(1)  to one decimal place and the Maclaurin polynomial of order 5 provides an estimate that is accurate to 2 decimal digits.

To answer Lab Question 2 you need to determine the value of n that provides an estimate that is accurate to 5 decimal digits.

>   

It is interesting to watch  the Maclauring polynomials converge to the exponential function. The simplest way to obtain an animation of this is

>    TaylorApproximation( f2, x=0, order=0..10, -5..5, output=animation );

[Maple Plot]

Notice how the higher-order Maclaurin polynomials provide a reasonable approximation to the exponential function on a larger interval (centered at x = 0 ).

>   

Example 3 - # 42

This problem asks us to bound the error R[4](x) for -0.5 <= x <= 0.5 for the fourth-order Maclaurin polynomial for

>    f3 := ln( (1+x)/(1-x) ):
f(x) = f3;

f(x) = ln((x+1)/(1-x))

>   

>    P[4,0] := TaylorApproximation( f3, x=0, order=4 );

P[4,0] := 2*x+2/3*x^3

>   

Our first view of the error that we are attempting to plot is seen in a plot of the y=f(x) and y=T[3,0](x):

>    TaylorApproximation( f3, x=0, order=4, -0.5..0.5, output=plot );

[Maple Plot]

From this it appears that T[3,0](x) is a very good approximation to f(x) on [ -0.5, 0.5 ]. A second view of the error is seen in the following plot of the difference between the function and the Taylor polynomial:

>    plot( f3-P[3,0], x=-0.5..0.5 );

[Maple Plot]

From this it appears as though the largest errors occur at the endpoints of the interval: x = -0.5 and x = 0.5. The precise formula for R[4](x) is

>    R[4] := simplify(TaylorError( f3, x=0, order=4 ));

R[4] := proc (x) options operator, arrow; -2/5*(5*c^4+10*c^2+1)/(c+1)^5/(-1+c)^5*x^5 end proc

In particular, when x = -0.5 and x = 0.5, the error bounds are

>    r1 := R[4](-0.5);
r2 := R[4]( 0.5);

r1 := .1250000000e-1*(5*c^4+10*c^2+1)/(c+1)^5/(-1+c)^5

r2 := -.1250000000e-1*(5*c^4+10*c^2+1)/(c+1)^5/(-1+c)^5

>    p1 := plot( r1, c=-0.5..0  , color=red,  legend=["R[4](-0.5)"] ):
p2 := plot( r2, c= 0  ..0.5, color=blue, legend=["R[4]( 0.5)"] ):
display( [p1,p2] );

[Maple Plot]

The largest errors obviously occur at the endpoints:

>    r3 := eval( r1, c=-0.5 );
r4 := eval( r2, c= 0.5 );

r3 := -.2008230452

r4 := .2008230452

This means

 -0.2008 <= f(x)-T[4,0](x)  = R[4](x)  <= 0.2008

or

  abs(f(x)-T[4,0](x))  = abs(R[4](x))  <= 0.2008. for all -0.5 <= x  <= 0.5.

Thus, an error bound for the fourth-order Maclaurin polynomial for f(x) = ln((1+x)/(1-x))  on -0.5 <= x  <= 0.5 is

   abs(R[4](x))  <= 0.2008. for all -0.5 <= x  <= 0.5.

>   

Example 4 - Application of # 42

The result in Example 3 can be very useful. For example if you want compute the definite integral

>    q1 := Int( f3, x=0..1/2 ):
q1;

Int(ln((x+1)/(1-x)),x = 0 .. 1/2)

There are several options. First, the definite integral could be evaluated exactly. An antiderivative can be found by rewriting ln((1+x)/(1-x)) as ln(1+x) - ln(1-x) and then integration by parts to evaluate each integral. This is a long - and difficult - set of operations. An alternate method for approximating the integral is to replace the integrand with a Taylor (Maclaurin) polynomial with remainder term:

  Int(ln((1+x)/(1-x)),x = 0 .. 1/2) = Int(P[4,0]+R[4](x),x = 0 .. 1/2)  

so that

  Int(abs(ln((1+x)/(1-x))-T[4,0]),x = 0 .. 1/2) <= Int(abs(R[4](x)),x = 0 .. 1/2)                              

           ``  <= Int(.2008,x = 0 .. 1/2)  

   `` = .1004  

To conclude, note that

>    q2 := Int( P[4,0], x=0..1/2 ):
q2 = value(q2);
 `                                     ` = evalf(q2);

Int(2*x+2/3*x^3,x = 0 .. 1/2) = 25/96

`                                     ` = .2604166667

and the error in this result is no more than 0.1004.

Maple will perform the exact integration without complaint. The result of this calculation is

>    q1 = value(q1);
`                         ` = evalf(q1);

Int(ln((x+1)/(1-x)),x = 0 .. 1/2) = -2*ln(2)+3/2*ln(3)

`                         ` = .2616240719

From this calculation it is seen that the actual error is much smaller than 0.1004, but the results are consistent.

>   

Lab Questions

1. Modify Example 1 to provide a good estimte for abs(R[6](.5))  for f(x) = ln(2+x)  with a = 0 . (This is #33 in the text.)

2. Modify Example 2 to answer the question posed in #39.

    Bonus (2 pts): How many terms are needed to estimate exp(1)  to 15 decimal digits? What is this estimate?

    Hint: You will need execute the command such as Digits := 25:  to get Maple to work with more than 10 decimal places.

3. #41.

4. #43

5. #45

6. [Essay Question] (2 pts) Let f be a polynomial of degree n . Explain why P[n,a](x) = f(x)  for all x  and for all a .

>   

>   

>