Mathematics 36, section 1 -- AP Analysis

Lab Day 4: Taylor Polynomials, Approximations

October 1, 1997

Goals

In today's lab will use Maple to compute Taylor polynomial approximations, and use graphical and numerical methods to analyze the error.

Background

Recall from class on Monday and Tuesday that if

|f(n+1)(z)| <= M

for all z between x and a, then the error in the approximation of f(x) by pn(x) (the nth degree Taylor polynomial at a) is bounded as follows

(1) |f(x) - pn(x)| <= (M/(n+1)!) |x-a|n+1

Taylor Polynomials in Maple

Maple has a ``built-in'' function called taylor that can be used to compute Taylor polynomials of functions. The general format is

taylor(f(x),x=a,d);

where f(x) is the function to be approximated, a is the x-value where the Taylor polynomials will be expanded, and d >= 1 is an integer. For example, try entering:

taylor(sin(x),x=0,6);

Note two things:

1) The output

x - (1/6)x3 + (1/120)x5 + O(x6)

is a polynomial, plus another term -- O(x6) -- that describes the size of the error. The way to interpret this is that the error will go to zero like x6 (at least) as x -> 0.

2) The 6 in the Taylor command is one more than the degree of the polynomial. To get the nth degree polynomial, you will always want to take d = n + 1. To get rid of the error term, you can ``nest'' the taylor command inside a convert command like this:

convert(taylor(sin(x),x=0,6),polynom);

Another new Maple Command

Frequently in larger-scale computations, we want to repeat a computation, say for each value of a number n starting from n=a up to n=b. Maple provides several different mechanisms for repetition of a command. Perhaps the simplest one is the seq (``sequence'') function. If you enter a command

seq(command,n=a..b);

then the command (whatever it is) will be repeated once for each integer value of n between a and b (inclusive), and the output from all will be combined into a single sequence of values. For instance, try entering the following command:

seq(n^3,n=1..12);

to get the idea. The command inside the seq can be any other Maple command, typically involving the variable n in some way. Here is a more involved, example, which will invoke the taylor command Taylor polynomials for f(x) = ex of degrees 0,1,2,...,10:

seq(convert(taylor(exp(x),x=0,n),polynom),n=1..11);

(recall the ``shift'' in the taylor function described above; for example taylor(exp(x),x=0,5) computes p4(x)!)

Lab Questions

1) In this question, you will generate a plot of sin(x), together with its Taylor polynomials at a=0, of degrees n = 1,3,5,7,9 together on the same axes for -5 <= x <= 5.

a) First generate the set of polynomials with this command:

pset := {seq(convert(taylor(sin(x),x=0,2*n),polynom),n=1..5) };

(Do you see why this works?)

b) Next, to plot the Taylor polynomials together with sin(x) on -5 <= x <= 5, use:

plot(pset union {sin(x)}, x = -5..5);

Your initial plot may not look too promising; if so examine the scale on the y-axis. To plot only the part of the graphs for -5 <= x <= 5 and -2 <= y <= 2, for instance, you can add a range of y-values: y=-2..2 after the range of x-values in the plot command.

2) Describe in words what happens as the degree of the Taylor polynomial increases. Do the approximations for a given x in [-5,5] get better? Does the interval where the approximation is ``really good'' change? How?

3) Make a table of values (using the error bound for Taylor polynomials as in (1) above) giving the biggest possible error for the Taylor approximations tosin(x) given by pn(x) on [-5,5] for each of the degrees n = 1,3,5,7,9. (All the computations here can be done with the seq command in Maple!) How does your answer in 2) relate to these computations with the error bound?

4) What is the smallest value of n for which the Taylor polynomial of degree n (always with a = 0) approximates sin(x) with 3 decimal digit accuracy for all x between -5 and 5? Use the error bound (1).

Lab Writeups Due:

Wednesday, October 8.