Mathematics 134 -- Intensive Calculus for Science 2
Lab Day 3: Taylor Polynomials, Approximations
April 9, 2002
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 Monday that if
f is a function that is n-times differentiable
at x = a, then there is a unique 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) --
describes
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.
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
In these questions, you will generate plots of sin(x),
together with its Taylor polynomials of degrees n = 3,5,7,9,11
at a = 0 and compare the
accuracy of the Taylor approximations.
- First plot sin(x) and it Taylor polynomial of degree
3 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 sine function:
p3 := convert(taylor(sin(x),x=0,4),polynom);
plot({sin(x), p3}, x=-Pi..Pi);
Note: There is no (x) after the p3 in the
plotting command; we computed the Taylor polynomial as an expression
in the command before, assigned it to the symbolic variable p3
and then used that expression in the plot command.
- Now plot the absolute error function: abs(sin(x)-p3).
What is the largest the absolute error gets on this interval?
- Repeat part 1 for the Taylor polynomial of degree 5 of sin(x)
at a = 0.
- Does using the fifth degree polynomial to
approximate sin(x) seem to yield better
results than using the polynomial of degree 3? For instance,
is the absolute error for this polynomial smaller than the absolute
error for p3 (x) on the whole interval?
- Repeat part 1 for the Taylor polynomials of degree 7, 9, 11 of sin(x)
at a = 0. When you graph the polynomials of degree 9 and 11 together
with the sine 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 "diverge". When does that happen for the degree
9 polynomial? When for the degree 11 polynomial?
- 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? Will the corresponding interval grow to
arbitrary length as n increases, or is there a "limit" to
its size? Explain.
Lab Writeups Due:
Tuesday, April 16.