Mathematics 134 -- Intensive Calculus for Science 2

Lab Day 3: Taylor Polynomials, Approximations

March 29, 2006

Goals

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

Background

Recall from class on Tuesday that if f is a function that has n derivatives at x = a, then there is exactly one polynomial pn of degree <= n whose first n derivatives at x = a are the same as the corresponding derivatives of f at x = a. pn is called the nth degree Taylor polynomial of f at x = a, and can be computed by the formula:

pn(x) = f(a) + f'(a)(x-a) + f''(a)(x-a)2/2! + f'''(a)(x-a)3/3! + ... + f(n)(a)(x-a)n/n!

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 the following command which computes the 5th degree Taylor polynomial for f(x) = ex at a = 0:

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

Note two things:

1) The output

1 + x + (1/2)x2 + (1/6)x3 +(1/24)x4+ (1/120)x5 + O(x6)

is a polynomial, plus another term. The other term -- O(x6) -- is intended to describe the size of the error. The way to interpret this is that the error will go to zero like (a constant times) x6 (at least) as x -> 0. To get rid of the error term, you can ``nest'' the taylor command inside a convert command like this:

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

Try this and note the output. You should use this convert step every time you want just the Taylor polynomial, without the error term.

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.

Lab Questions

A) In this questios, you will generate plots of cos(x), together with its Taylor polynomials of degrees n = 2,4,6,8,10 at a = 0 and compare the accuracy of the Taylor approximations.

  1. First plot cos(x) and it Taylor polynomial of degree 2 together on the same axes with -Pi <= x <= Pi. You can use these commands, for instance, first to compute the Taylor polynomial, assign it the name p3, then plot it with the cosine function:

    p2 := convert(taylor(cos(x),x=0,3),polynom);

    plot([cos(x), p2], x=-Pi..Pi,color=[blue,red]);

    Note: The cos(x) will be the blue graph and the polynomial will be the red graph -- the colors match the order in the list of functions. There is no (x) after the p2 in the plotting command; we computed the Taylor polynomial as an expression in the command before, assigned it to the symbolic variable p2 and then used that expression in the plot command.

  2. Now plot the absolute error function: abs(cos(x)-p2). What is the largest the absolute error gets on this interval?

  3. Repeat parts 1 and 2 for the Taylor polynomial of degree 4 of at a = 0.

  4. Does using the fourth degree polynomial to approximate cos(x) seem to yield better results than using the polynomial of degree 2? For instance, is the absolute error for this polynomial smaller than the absolute error for p2 (x) on the whole interval?

  5. Repeat parts 1 and 2 for the Taylor polynomials of degree 6, 8, 10 of cos(x) at a = 0. When you graph the polynomials of degree 8 and 10 together with the cosine function, you may actually only see one graph on the interval -Pi <= x <= Pi. What does that mean? Try plotting a bigger range of x-values until you see the graphs start to "split apart". When does that happen for the degree 8 polynomial? When for the degree 10 polynomial?

B) Now, consider the function f(x) = ln(1+x), expanding around a = 0. Plot the Taylor polynomials of degrees 1, 2, 3, 4, 5 and the function on the interval -1 < x < 1. For each degree, find an interval where the Taylor polynomial of that degree approximates f(x) to within 10-3 -- that is: abs(f(x) - pn(x)) < 10-3 for all x in the interval. How do the intervals change as n increases? For instance, does it seem that the interval will grow to arbitrary length as n increases, or is there a "limit" to its size? Explain.

Lab Writeups Due:

Monday, April 3.