> restart;
>
Taylor Polynomials and Taylor Series
Syntax for Taylor Polynomials
Maple can easily find Taylor polynomials even for very complicated functions. The example below illustrates the proper syntax.
Example 1.
Consider the function
. Find and graph the first two Taylor polynomials
,
of
at
. How well do they approximate the function
at x=0.3?
Let's define the function
.
> f:=x->1/(1+2*x);
>
To find the first and the second Taylor polynomials, we apply first the command " taylor ". For convenience, we shall label outputs by T1 , T2 .
> T1:=taylor(f(x),x=0,2); T2:=taylor(f(x),x=0,3);
>
The first argument under the command "
taylor
" is your function, the second a point
at which you wish to expand the function into its Taylor series, in this case
, the third is responsible for the order of the polynomial that you will see. Note that the polynomial that you obtain is one degree less than the third argument. The command
"taylor
" returns
not a polynomial
but the Taylor
series
at
, in which a few first terms and a remainder are displayed. The remainder is denoted, in general, by
.
, in this context, stands for a sum of terms of order at least n in
, that is, terms containing
in the power of at least n. It is important to realize that
T1
,
T2
are series and not polynomials, as many commands, for example "
plot
", will not work with series. You can convert
T1
,
T2
into corresponding polynomials using the following command:
> convert(T1,polynom); convert(T2,polynom);
>
If you want to avoid annoying labeling or the use of the symbol " % ", you can apply " taylor " and " convert " commands together. Let's do it, and label the corresponding polynomials by P1 , P2 . Note the proper use of parentheses.
> P1:=convert(taylor(f(x),x=0,2),polynom); P2:=convert(taylor(f(x),x=0,3),polynom);
>
Now we shall plot
and the two polynomials. Usually when plotting functions we have to worry about the x-range only. Maple adjusts the y-range automatically, so the whole graph is visible. It doesn't work very well if a function has a vertical asymptote, as
has at
. In such cases it may be a good idea to specify the range for y, as well. The proper syntax looks as follows.
> plot([f(x),P1,P2],x=-1..1,y=-5..10,color=[black,red, blue],thickness=[2,1,1]);
>
We see the thicker, black graph of the original function and the graphs of the first two polynomials. Maple displays also the vertical asymptote
. If you find it distracting, you can prevent the asymptote from showing by adding "
discont=true
" under the plot command.
Observe that the command " convert(taylor(....),polynom) " returns the corresponding Taylor polynomial as an expression in terms of x and not as a function of x. Hence, if you want to evaluate polynomials at a given x, you have to use the command "subs " . For example, let's compare the values of the two polynomials and the function f at x = .0.3.
> f(.3); subs(x=.3,P1); subs(x=.3,P2);
As we see, neither polynomial gives a very good approximation of the function
at x = 0.3.
>
Intervals of Convergence
You can use Maple to graph Taylor polynomials of higher order together with the original function. Such graphs can illuminate the idea of the interval of convergence.
Example 2.
Let again
. Find a few higher-order Taylor polynomials of
at
. Graph the polynomials and
in one coordinate system. Can you guess the radius of convergence of the Taylor series of
at
? Examine your guess graphically and numerically. Confirm your guess analytically by finding the exact value of the radius of convergence.
To save ourselves a lot of typing we shall use lists and the "
seq
" command. We shall generate and then plot a list consisting of the original function
and consecutive polynomials of orders, say, 4 to 10. It will save us the effort of writing a separate command for each polynomial. Let's call our list "
L
".
> L:=[f(x),seq(convert(taylor(f(x),x=1,i),polynom),i=5..11)];
>
As we see, Maple simplified the two initial terms,
, in each Taylor polynomial to
. The "
plot
" command can be applied directly to a list of expressions. (All elements of
L
are expressions. Technically, f is a function, but f(x) is an expression in terms of x).
> plot(L,x=-1.5..3.5,y=-5..10,color=[black,blue,cyan,green,yellow,brown,red,magenta],thickness=[2,1,1,1,1,1,1,1]);
>
Our best guess based on the picture is that the radius of convergence R is about
. Indeed, for x > 1+
, the polynomials seem to sharply diverge from
. As a matter of fact, the higher order of the polynomial, the faster it diverges from the graph of
for x > 1 +
. Look at the colors of the graphs: magenta and red correspond to two highest-degree polynomials on the list. The situation with divergence is even more clear on the other side, for x < 1-
. The polynomials are all positive, while the values of
are negative. We are guessing then that the radius of convergence is at most
. Within the interval (1-
, 1+
) the polynomials seem to be getting closer and closer to
. Hence, the radius of convergence seems to be, indeed,
. Be warned, however, that the emphasis in the reasoning presented above should be on the word "
guess
". As you know, some Taylor series converge very fast, some very slowly. You can never be sure that the polynomials that you are graphing are representative of the behavior of a given series.
Let's try to confirm our guess that R is about
by graphing a couple of really long polynomials, say, of orders 20 and 25.
> plot([f(x),convert(taylor(f(x),x=1,21),polynom),convert(taylor(f(x),x=1,26),polynom)],x=-1.5..3.5,y=-5..10,color=[black,blue,magenta],thickness=[2,1,1]);
>
The graph seems to confirm our conjecture. You can, of course, experiment on your own by changing the values or ranges for i in the commands above and graphing longer and longer polynomials. Be aware, however, that calculating and graphing very long polynomials may take a while. If you start calculations that take longer than your patience allows, click on the " STOP " button on the tool bar. It will stop calculations, although usually not right away.
We can try to examine our guess as to the value of R numerically, by looking at values of Taylor polynomials near
and
versus the corresponding values of
. Let's create a list of numerical values of
and polynomials of orders, say, 50 through 60 at x = 2.3.
> [evalf(f(2.3)),evalf(seq(subs(x=2.3,convert(taylor(f(x),x=1,i),polynom)),i=51..61))];
>
Remember that the first number on the list represents
, the following numbers represent the values of consecutive Taylor polynomials
through
. The values of the polynomials do seem to converge to
. Hence, x = 2.3 is within the interval of convergence, which suggests that R is at least 2.3-1= 1.3. Let's check the values
versus
through
.
> [evalf(f(2.7)),evalf(seq(subs(x=2.7,convert(taylor(f(x),x=1,i),polynom)),i=51..61))];
>
The values oscillate wildly, which suggests that x = 2.7 is outside the interval of convergence, or equivlantly, that R is less or equal to 2.7-1=1.7. By modifying the commands above, you can explore numerically convergence and divergence at points near the other end of the interval of convergence, that is, near x = -0.5. Note that when your test points get closer to the endpoints -0.5 or 2.5 convergence or divergence became much slower.
In our example, both numerical and graphical experiments seem to confirm our guess that R is equal to
.
Warning: Graphical and numerical experiments may lead to good guesses as to the value of the radius of convergence, but they can also be very misleading. The appearance of graphs depends heavily on the range for x and y, which can be very confusing. Convergence or divergence may be so slow that your numerical experiments will not pick it up.
>
The only way to be sure that the radius of convergence in our example is indeed
is to prove it analytically. Fortunately, it is quite easy. We can obtain the Taylor series for
at
from the expansion of
at
, which is the geometric series:
.
To get a series involving powers of
we so some algebraic juggling to rewrite
as follows:
=
=
=
.
From the uniqueness of power series expansion, the latter series is the Taylor series of
at
. Indeed, it is a power series at
and it converges to
in a neighborhood of
. Hence, it must be the Taylor series of
at
. On the other hand, for any given x, the series is equal to the constant
times the geometric series with ratio
. Hence, the series converges if and only if
, that is when
. Thus, the radius of convergence is indeed
.
Yet another way to see this is to use the formula
with
, as in the text.
Similarly, using the expansion of
, we can easily obtain the Taylor series of
at
:
,
whose radius of convergence is
. A conjecture that comes to mind is that the Taylor series at
of any function is convergent in a symmetric interval around
which can be extended until we hit the first "singularity" of the function. A "singularity" is a point at which the behavior of the function is "irregular", like, for example, a point of a vertical asymptote. Is this conjecture true? Yes, but only provided we look at singularities in the complex plane as well. If we consider only singularities located on the real line, the conjecture is false. It is demonstrated by the example in Problem 1 of your homework. The function that you have there has no singularities on the real line, yet the radius of convergence of its Taylor series at x = 0 is finite.
>
Estimating the Error of Approximation by Taylor Polynomials
Let
be a given function,
a given point,
the n-th Taylor polynomial of
at
. Let
be the n-th error. We know an error bound for Taylor approximations. Namely:
for all x in [ a-d, a+d ] , (EB)
where
is such a constant that
for all x in [ a-d, a+d ] .
denotes the (n+1)-th derivative. We denote the error bound by (EB) for future reference. This bound is of great importance for proving convergence of Taylor series, for obtaining estimates of the error for arbitrarily long Taylor polynomials, and for many other tasks. You have to remember that the formula (EB) gives an upper bound for an error and not its exact value. The actual error is often much smaller than the estimate (EB). If we work with specific functions and specific polynomials, we don't always have to use (EB). We can simply graph the error and obtain the estimate from the graph.
>
Example 3.
Consider the function
. Find the smallest-degree Taylor polynomial at
that stays within 0.1 of the function
for all x in the interval [-2,2]. ( Observe that in this problem the interval is fixed and we are looking for a polynomial that gives the desired approximation in this interval.)
>
We shall solve the problem by graphing the errors
corresponding to a few first polynomials. Let's generate a list of errors corresponding to consecutive polynomials and plot them in the interval [-2,2].
> h:=x->exp(x)*sin(x);
>
> E:=[seq(h(x)-convert(taylor(h(x),x=0,i),polynom),i=2..11)];
>
We shall plot a few error functions at a time, so we don't get confused which is which. We shall also plot the horizontal lines y= -0.1, y = 0.1 to see which errors stay within the bounds. Remember that E[k] denotes the k-th element of the list E. We observe that E[3]=E[4] and E[7]=E[8], so we shall not plot E[4] and E[8].
> plot([-.1,.1,E[1],E[2],E[3],E[5]],x=-2..2,color=[magenta,magenta,red,blue,green,yellow]);
>
Clearly, none of the errors plotted above stays within bounds. Hence, the first five polynomials are not good enough.
> plot([-.1,.1,E[6],E[7],E[9],E[10]],x=-2..2,color=[magenta,magenta,red,blue,green,yellow]);
>
The first error function which stays within bounds is E[7]. Hence, the seventh Taylor polynomial is the first that approximates
in [-2,2] within 0.1.
>
Example 4.
Let
be as above. Find the thirties Taylor polynomial
of
at x =0. Find the longest interval around zero, [-d,d], such that
stays within 0.01 of
for all x in [-d,d]. (Observe that in this problem the Taylor polynomial is fixed and we are looking for an interval in which the desired approximation is valid.)
>
Let's find the polynomial
and label it P30:
> P30:=convert(taylor(h(x),x=0,31),polynom);
>
Lets define the error of the 30-th degree polynomial:
> E30:=h(x)-P30;
>
Let's graph the error E30 together with the lines y = -0.01, y= 0.01 to see in what interval it stays within bounds.
> plot([.01,-.01,E30],x=-8..8,color=[magenta,magenta,blue]);
>
For your information, it took a few trials and errors as to what the range for x should be to obtain the above graph. To pinpoint the interval for which the error stays within bounds, we solve a couple of equations.
> a:=fsolve(E30=0.01,x,-8..-6); b:=fsolve(E30=-0.01,x,6..8);
>
(Be aware that it takes a little while for Maple to execute the seond command and find "b". Don't panic.) The error stays within bounds in the interval [a,b]. If we want a symmetric interval around zero in which the error stays within bounds, it will have to be [-a,a].
Example 5.
Find a polynomial whose value at x = 0.7 approximates
to thirty decimal places. Check the accuracy of your approximation
without
using Maple's value of sin(.7)!
>
Of course, we are going to use Taylor series of sin(x) at x = 0 and look for a Taylor polynomial that gives a desired approximation. Since we are not asked to find the polynomial of smallest degree, we shall use the estimate (EB), rather than check consecutive polynomials one-by-one. Since any derivative of sin(x) is either plus or minus sin(x) or cos(x), the absolute value of any derivative is bounded by 1 in any interval. Hence, the bound for the error
for any x is given by:
.
Hence, to find a polynomial that approximates sin(0.7) as well as we want, we have to find n such that
. In other words, we have to find n such that
,
or, equivalently:
.
Maple can solve many inequalities, but the one above is too tricky to be solved with simple commands. Let's find a suitable n by trial and error. Define
> S:=.7^(n+1)/factorial(n+1)-10^(-30);
Let's find a positive integer n for which S is less than zero. As n increases, S decreases, we try n = 20, S is positive. We try n= 30, S is negative. By trial and error we find that the smallest n for which S is negative is n =25.
> subs(n=25,S);
>
Hence, Taylor polynomial of degree 25 approximates sin(.7) with desired accuracy. Let's find the polynomial and compare it's value at x = .7 with Maple's value for sin(.7), which presumably is accurate to the number of digits shown.
> P25:=convert(taylor(sin(x),x=0,26),polynom);
>
Since Maple's default setting shows only ten decimal places when evaluating numerically, we have to tell Maple that we want expansion up to 30, or better yet 31 digits, for values of sin(x) and P25 at x =.7. We accomplish that by the following command:
> evalf(sin(.7),31); evalf(subs(x=.7,P25),31);
>
The second argument under the " evalf " command tells Maple how many digits you want to see. Keep in mind that Maple uses techniques similar to Taylor polynomials to compute its values for sin(.7).
>
Homework Problems
After opening your homework worksheet type in and execute the command " restart; " to clear any variable assingment from this worksheet like f, g, P20 etc.
Problem 1.
Consider the function
.
(a) Analytically, that is, "by hand", find the Taylor series of
at x = 0. (You can do it by substituting into the well-known expansion for
at x=0.) Find the exact value of the radius of convergence of the series. (Since no odd powers appear in the expansion, you can't use the ratio test. Use the properties of the geometric series that you know.) Explain how you arrived at your answer. Use the math equation mode of Maple to type in your series and other mathematical formulas, if you need them. ( Instructions for doing this are found below.)
(b) As in Example 2, illustrate graphically the interval of convergence by plotting
and a few higher-order polynomials in one coordinate system. Find polynomials and ranges for x and y that allow you to generate a really convincing picture.
Note that the center of the series is x=0 and not x=1, as in Example 2. Make appropriate adjustments in the syntax!
(c) At a couple of points near one of the endpoints of the interval of convergence, one point inside the interval, one point outside the interval, demonstrate numerically convergence or divergence of the series by evaluating higher-order Taylor polynomials at those points and comparing with the corresponding values of f.
Instructions for Using the Equation Mode:
When you are in the text mode and want to enter a math equation, positon the cursor where you want the formula to appear and click on the button "
" on the toolbar, right next to the "T" button. The cursor changes to a question mark. Start typing your formula using the standard Maple syntax. For example, if you want to enter:
, type:
7*sum((n+1)/(2^n)*(x-1)^n,n=0..infinity)
. The text that you type will appear in a small strip at the bottom of toolbar. After you finish typing your formula, press "ENTER", and then click on "T". The formula will appear where you wanted it and the cursor after it. Be prepared to see Maple rearrange the formula a bit, as well as what you typed in the strip, to its own liking. As long as it is mathematically equivalent to what you wanted, live with it. If you want to edit formula you typed already, highlight it, click on the small strip where the syntax is to place cursor there, edit the equation, press "ENTER", click on "T".
There are things that Maple will not allow you to do. For example, you cannot enter a formula of the form "a=b=c". You have to enter "a=b" and "b=c", separately.
Problem 2.
Consider the function
.
(a) Find the smallest-degree Taylor polynomial at x =0 which approximates the function within 0.2 throughout the interval [-1,1].
(b) Find the 20-th degree Taylor polynomial
at x = 0. Find the longest interval [-d,d] about x = 0 in which the polynomial stays within 0.1 of
.
Problem 3. Find a polynomial which approximates cos (0.4) to twenty decimal places. Compare the two values at x = 0.4.
Problem 4. Using the ratio test and Maple's " limit " command to find the radius of convergence of the power series
.
Hint: The proper syntax for finding limits of sequences is: limit( expression in terms of n, n=infinity); .
MTH 142 Maple Worksheets written by B. Kaskosz and L. Pakula, Copyright 1999.
Last modified August 1999.
>