Mathematics 132 – Calculus for Physical and Life Sciences 2 Lab Day 4: Visualizing Convergence of Taylor Series, Approximations April 11, 2008 – Lab Writeups due in class on Monday, April 21.

Goals

In today’s lab will use Maple to compute Taylor polynomials, and use graphical and numerical methods to understand the convergence of Taylor series.

Background

Recall from class on Wednesday that if f is a function that has derivatives of all orders, then its Taylor series at x = a is

∑_{n=0}^{∞} \frac{f^{(n)}(a)}{n!}(x − a)^{n}

and provided that this series converges on some interval, it defines a function whose nth derivative at x = a is the same as the nth derivative of f(x) for all n. If we take the partial sums of the Taylor series, we obtain Taylor polynomials. There is exactly one polynomial p_{k}(x) of degree ≤ k whose first k derivatives at x = a are the same as the corresponding derivatives of f at x = a. The Taylor polynomials of f at x = a are computed by the formula:

p_{k}(x) = f(a) + f′(a)(x − a) + \frac{f′′(a)}{2!}(x − a)^{2} + \frac{f′′′(a)}{3!}(x − a)^{3} + ⋯ + \frac{f^{(k)}(a)}{k!}(x − a)^{k}.

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) = e^{x} at a = 0

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

Note two things:

(1) The output

1 + x + (1/2)x^{2} + (1/6)x^{3} + (1/24)x^{4} + (1/120)x^{5} + O(x^{6})

is a polynomial, plus another term. The other term – O(x^{6}) – is intended to describe the size of the error if we use this polynomial to approximate e^{x}. The way to interpret this is that the error will go to zero like (a constant times) x^{6} (at least) in the limit 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 in the Maple command. This is one case where you don’t want to ask “why?” Just accept that this is the way Maple is set up!

Lab Questions

(A) In this question, you will generate plots of cos(x), together with its Taylor polynomials of degrees n = 2, 4, 6, 8, 10 at a = 0 and visualize what is happening as more and more terms are added into the Taylor polynomials.

(1) First plot cos(x) and it Taylor polynomial of degree 2 together on the same axes with −π ≤ x ≤ π. You can use these commands, for instance, first to compute the Taylor polynomial, assign it the name p2, 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]);

Notes: a. 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. b. 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.

c. When you hand in your lab write-ups, since you will probably be printing out your work on a black and white printer, please put in labels by hand showing which graph is which.

(2) Now plot the absolute error function: | cos(x) − p_{2}(x)|. (In Maple, the absolute value function is called abs.) What is the largest difference between cos(x) and p_{2}(x) on this interval?

(3) Repeat part (1) for the Taylor polynomial of degree 4 of cos(x) 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 p_{2}(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 −π ≤ x ≤ π. 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 again.

(1) Plot the Taylor polynomials of degrees 1, 2, 3, 4, 5 and the function on the interval −1 < x < 1.

(2) For each degree, find an interval where the Taylor polynomial of that degree approximates f(x) to within 10^{−3} – that is: |f(x) − p_{n}(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 on one end or the other?

Lab Writeups due: In class on Monday, April 21.