Laboratory 24
Taylor Series andTaylor Polynomials
Introduction
We approximate a function by its Taylor polynomials of different orders. We also use Taylor series to evaluate limits.
Example 24.1
Recall Taylor's Theorem, which says the following.
Taylor's Theorem. Let
be an
times differentiable function on an open interval
. Then for any
and any
in the interval ![]()
![FormBox[RowBox[{f(x), =, RowBox[{RowBox[{Underoverscript[∑, k = 1, arg3] f^(k)(a)/k ! (x ... ) (x - a) + 1/2 ! f'' (a) (x - a)^2 +... + 1/n ! f^(n)(a) (x - a)^n + R_n(x)}]}], TraditionalForm]](HTMLFiles/index_7.gif)
where
![]()
The polynomial
is called the Taylor polynomial of order
for
at
. The term
is called the remainder, and it represents the error made when approximating the function by its Taylor polynomial.
Let us use Mathematica to find the Taylor polynomial of order 5 for the function
at
. We begin by defining the function.
To calculate the higher derivatives of
, we shall use the Mathematica command D[f[x],{x,k}], which gives us the kth derivative of the function
. Let us illustrate the command.
Because we are going to want the value of the derivative when
, we need to use the substitution operator /. as follows.
The last thing that we need to do is form the sum; we can do that with the aid of the
command available on the basic input palette. Thus, the fifth order Taylor polynomial for
at
is
If, on the other hand, we want the Taylor polynomial of degree 6 for
at
, we would execute the following.
Because of the complexity of this problem, Mathematica has a built in command Series to generate a Taylor polynomial. The Mathematica command Series has four parameters: the expression whose Taylor polynomial we want; the variable used in the expression; the point that we expand about; and an integer which is the order of the Taylor polynomial. We want to have a Taylor polynomial for
of order 5, expanded about 0.
Series[f[x], {x,0,5}]
This agrees with the result of our previous calculation, save for the extra term
. To understand the meaning of this term, we need to understand the notation. We say that a quantity
is of order
, written
if there is some constant
so that
. Return to the statement of Taylor's theorem, and examine the remainder term. If
, and we look for the fifth order Taylor polynomial, then the remainder term
satisfies the relationship
, where
. Thus,
, and Mathematica indicates this fact by including this form of the remainder term in the ourput produced by the Series command.
Suppose instead we wnat the Taylor polynomial of degree 6 for
at
; then we would execute the following.
Series[f[x],{x,π,6}]
We use the Mathematica command Normal to convert a Taylor series to a Taylor polynomial, by dropping the O[x] term.
Normal[Series[f[x],{x,0,5}]]
Experiment 24.1
Find the Taylor polynomial of the indicated order about the indicated point for each of the following functions.
1.
, order 6 about
.
2.
, order 7 about
.
3.
, order 8 about
.
4.
, order 6 about
.
5.
, order 7 about
.
Example 24.2
We want to compare graphically a function with its Taylor polynomials of different orders. Consider the function
.
f[x_]:=x^2 Cos[x]
p1=Plot[f[x],{x,0,2 Pi}];
We want to compare
graphically with its polynomials, near
. We start with the Taylor polynomial of order 3.
taylorpoly3[x_]=Normal[Series[f[x],{x,Pi,3}]]
Note that we used the immediate assignment operator = instead of the more usual delayed assignment operator :=. To see that this is important, let us examine the following.
On the other hand, if we used delayed assignment, we would obtain an error.
Let us compare the graphs of
and its third order Taylor polynomial at
.
Plot[{f[x],taylorpoly3[x]}, {x,0,2 Pi},PlotStyle->{ {},RGBColor[1,0,0]}];
We increase the order of the Taylor polynomial first to 6 and then to 9.
taylorpoly6[x_]=Normal[Series[f[x],{x,Pi,6}]]
Plot[{f[x],taylorpoly6[x]}, {x,0,2 Pi},PlotStyle->{ {},RGBColor[1,0,0]}];
taylorpoly9[x_]=Normal[Series[f[x],{x,Pi,9}]]
Plot[{f[x],taylorpoly9[x]}, {x,0,2 Pi},PlotStyle->{ {},RGBColor[1,0,0]}];
We see that the approximation is getting better and better as we increase the order of the Taylor polynomial. To better see the error, plot the difference. For example, to see the magnitude of the difference between
and its 6th order Taylor polynomial near
we may use the following command:
taylorpoly6[x]
Plot[Abs[f[x]-taylorpoly6[x]],{x,0,2 Pi}, PlotRange->All ];
The graph yields an interval [2,4] in which the polynomial appears to be a reasonable approximation of the function.
To get a more reliable estimate of the error term involved, we consider the remainder term in Taylor's Theorem. Recall that
![]()
In general it is difficult to compute the exact value of the right hand side, because of the difficulty in determining the value of
. However, the statement remains true if we replace
by a number
which is even larger.
In the above example, we analyze the remainder on the interval [0,6]. First,
for all
in the interval. Second, we calculate and graph the seventh derivative of
From the graph we estimate
to be less than 80. [Why can't we use 60?] Therefore,
. An upper bound for the error term is:
We conclude tht on the interval
that the difference between the function and its sixth order Taylor polynomial is at most 47.95. If we compare this with the graph, we see that this is in fact the case.
Next we estimate the error on the interval
. In this case,
, while
<1 on this interval. Hence, an upper bound for the error term is:
In this case, the error associated with the Taylor polynomial of order 6 is at most 0.0119048 on the interval [2,4].
Experiment 24.2 a
Consider the function
.
1. Gradually increase
, the order of its Taylor polynomial centered at π, until you have a good approximation on the interval [1,5]. Try at least three different values for n and show your graph for each. Justify graphically why your last value of
gives a good approximation.
2. Suppose you wish to approximate
on the interval [2,4] by an
order Taylor polynomial
(x) expanded about
to within an error of 0.005. By plotting the absolute value of the difference
, experimentally find the smallest
that is adequate. Show your final graph of the absolute value of
. The Mathematica command for the absolute value is Abs.
3. Use the error expression to estimate the error that appeared in question 2.
4. Repeat part 1 above for the function
centered at
, on the interval
.
Experiment 24.2 b
For each of the following functions determine its Taylor polynomial of order 5 expanded about
. Graph the function and the polynomial, and use the graph to give an interval in which the polynomial appears to be a reasonable approximation of the function. Then on that interval, estimate the error using the error expression.
1. ![]()
2. ![]()
3
.
Example 24.3
We use series to help to calculate limits like
. Often there is no problem. In some situations,however, such a limit has the indeterminate form "0/0 ". One way to handle this complication is to use L'Hôpital's rule, and another way is to use series.
For example, suppose we want to calculate
.
If we sumply substitute in the value
in the numerator and denominator, we obtain an indeterminate expression.
f[x_]:=Cos[2 x]-1;
g[x_]:=E^(-x^2)-1
f[0]
g[0]
We can calculate the Taylor series of each function about
.
fseries=Series[f[x], {x,0,4} ]
gseries=Series[g[x], {x,0,4} ]
Now divide the first by the second
fseries/gseries
The last term is
, so we know that it tends to zero as
. Consequently, we have
.
Experiment 24.3
Use a series approach to evaluate
1.
.
2.
.
Credits
These laboratories were created by Raouf Boules, Geoff Goodson, Ohoe Kim and Mike O'Leary for use in the Calculus courses of Towson University. Commercial use is prohibited without permission of the authors. Non-commercial use is permitted, provided this credit section is retained.
Created by Mathematica (August 23, 2004)