Taylor Series with Maple
Copyright © 2002 by James F. Hurley, University of Connecticut Department of Mathematics, Unit 3009, Storrs CT 06269-3009. All rights reserved.
The interactive version of this Maple worksheet is in MSB 203, in the Math 116 course folder.
It illustrates the ideas associated with Taylor series and approximation of functions by Taylor polynomials.
1. Generating Taylor Series. Maple's taylor command generates as many terms n of the Taylor series for an infinitely differentiable function f as you like, about any base point a that you specify. The syntax of the command is
taylor(f(x), x = a, n);
where f(x) is the formula for the function. Execute the following to see the first 10 terms of the exponential series , the Maclaurin series for the exponential function about 0.
p_9 := taylor(exp(x), x = 0, 10);
The term is a built-in order-of-magnitude error estimate. In this case it reports that the size of the error in using the n th-degree Taylor polynomial to approximate f ( x ) = near the base point x = 0 has order of magnitude proportional to . This illustrates the general remainder estimate for Taylor polynomials (as stated for instance in Theorem 9 of Section 12.10 of James Stewart, Calculus 4th Edtion ). For the exponential function exp, that remainder estimate asserts that for n = 9 an upper bound for the remainder = exp( x ) - is a constant multiple of . Suppose we denote that constant by . Then Maple's output implies that
From direct application of the ratio test, or Exercise 35(b) of Section 12.6 of Stewart,
Calculus 4th Ed
. from the Math 116 Syllabus, recall that the series
is absolutely convergent for all real numbers
. Hence (from Theorem 6, Section 12.2, p. 743, of
From that and the above inequality (1), it thus follows that
= 0, that is,
the Taylor series for
for all real numbers
(Compare the foregoing with Example 2, Section 12.10 of
The following Maple routine illustrates how close the Taylor polynomial is to for x close to the base point 0 of the exponential series. Execute the code to see a plot of the graph of the natural exponential function displayed with that of over the interval [-1, 6].
Note : the output of the taylor command is not a polynomial, but rather a data set consisting of with an error estimate tacked on. The second command in the following routine converts that data to . (The first command makes the display command available, which is necessary for displaying graphs of two functions in different colors. Decrease the range of x to see why we did not use a shorter interval of the x -axis.)
p := convert(p_9, polynom );
graphone := plot ( p, x = -1...6, color = blue):
graphtwo := plot( exp(x), x = -1...6, color = red) :
Warning, the name changecoords has been redefined
Observe that only for values of x larger than 4 can the eye detect two colors in the plot. For small values of x it is impossible to distinguish the graphs from the x -axis.
What does the plot suggest about how tables of values of the exponential function are computed? For negative values of x , or fairly small positive values, the Taylor polynomials of expanded about x = 0 give values very close to . What if you need , or more generally have to study near x = 6? Since Taylor polynomials provide close approximations to their function f ( x ) for values of x close to a , it would be worthwhile to use Taylor polynomials about a nonzero base point a (in this case, a = 6).
In point of fact, in the 18th century the original tables of values for important transcendental functions like exponential and logarithmic functions, sine and cosine functions, etc., were calculated by Taylor-polynomial approximation. Today's calculators and computer compilers use a more sophisticated numerical computation, one that mathematicians and computer scientists developed to provide rapid and accurate function values.
2. Application: approximate integration
. For a typical transcendental function
, it is impossible to find a formula for its antiderivative any simpler than
. In such cases, evaluation of a definite integral for
must be carried out by numerical approximation. Especially for hand computation, it is often convenient to approximate
. As an illustration, consider Exercise 42 of Section 12.10 of Stewart,
Calculus, 4th Ed
42. Approximate to three decimal places.
Solution. Execute the following Maple routine to produce the Taylor polynomial . (Or, just about as easily, replace x in the Taylor series for cos x by .)
p_12 := taylor( cos(x^2), x = 0, 12 );
p := convert( p_12, polynom );
The output provides the first three nonzero terms of the Taylor series for cos
, and reports that the error in approximating cos
is proportional to
in the interval [0, 1/2] of integration, that error is thus minuscule. Integration of
over [0, 1/2] should therefore provide a close approximation to the definite integral of cos
over that interval. The following Maple routine summarizes the results of that approximation, which is quite simple to carry out by hand with a calculator.
apprx := int(p, x = 0..1/2);
How can we verify that, to the three decimal places asked for in Exercise 42, the value of the given definite integral actually is 0.497? Consider the integral of over [0, 1/2].
Observe that the right side of this expression consists of the first four terms of a convergent alternating series, which arises from term-by-term integration of the Taylor series for cos . By Theorem 2 of Section 12.9, over the interval [0, 1/2] the series of term-by-term integration of the Taylor series converges to the integral on the left side. The Alternating Series Estimation Theorem guarantees that the error in using the sum of first three terms to approximate that integral is at most the size of the first term of the alternating series not included in . That is, the error in using to approximate is at most the size of the last term on the right side above:
² Å 0.000009 < 0.0005.
So the approximation above is indeed accurate to at least three decimal places.