> 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 [Maple Math] . Find and graph the first two Taylor polynomials [Maple Math] , [Maple Math] of [Maple Math] at [Maple Math] . How well do they approximate the function [Maple Math] at x=0.3?

Let's define the function [Maple Math] .

> f:=x->1/(1+2*x);

[Maple Math]

>

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);

[Maple Math]

[Maple Math]

>

The first argument under the command " taylor " is your function, the second a point [Maple Math] at which you wish to expand the function into its Taylor series, in this case [Maple Math] , 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 [Maple Math] , in which a few first terms and a remainder are displayed. The remainder is denoted, in general, by [Maple Math] . [Maple Math] , in this context, stands for a sum of terms of order at least n in [Maple Math] , that is, terms containing [Maple Math] 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);

[Maple Math]

[Maple Math]

>

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);

[Maple Math]

[Maple Math]

>

Now we shall plot [Maple Math] 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 [Maple Math] has at [Maple Math] . 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]);

[Maple Plot]

>

We see the thicker, black graph of the original function and the graphs of the first two polynomials. Maple displays also the vertical asymptote [Maple Math] . 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);

[Maple Math]

[Maple Math]

[Maple Math]

As we see, neither polynomial gives a very good approximation of the function [Maple Math] 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 [Maple Math] . Find a few higher-order Taylor polynomials of [Maple Math] at [Maple Math] . Graph the polynomials and [Maple Math] in one coordinate system. Can you guess the radius of convergence of the Taylor series of [Maple Math] at [Maple Math] ? 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 [Maple Math] 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)];

[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]

>

As we see, Maple simplified the two initial terms, [Maple Math] , in each Taylor polynomial to [Maple Math] . 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]);

[Maple Plot]

>

Our best guess based on the picture is that the radius of convergence R is about [Maple Math] . Indeed, for x > 1+ [Maple Math] , the polynomials seem to sharply diverge from [Maple Math] . As a matter of fact, the higher order of the polynomial, the faster it diverges from the graph of [Maple Math] for x > 1 + [Maple Math] . 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- [Maple Math] . The polynomials are all positive, while the values of [Maple Math] are negative. We are guessing then that the radius of convergence is at most [Maple Math] . Within the interval (1- [Maple Math] , 1+ [Maple Math] ) the polynomials seem to be getting closer and closer to [Maple Math] . Hence, the radius of convergence seems to be, indeed, [Maple Math] . 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 [Maple Math] 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]);

[Maple Plot]

>

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 [Maple Math] and [Maple Math] versus the corresponding values of [Maple Math] . Let's create a list of numerical values of [Maple Math] 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))];

[Maple Math]
[Maple Math]

>

Remember that the first number on the list represents [Maple Math] , the following numbers represent the values of consecutive Taylor polynomials [Maple Math] through [Maple Math] . The values of the polynomials do seem to converge to [Maple Math] . 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 [Maple Math] versus [Maple Math] through [Maple Math] .

> [evalf(f(2.7)),evalf(seq(subs(x=2.7,convert(taylor(f(x),x=1,i),polynom)),i=51..61))];

[Maple Math]
[Maple Math]

>

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 [Maple Math] .

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 [Maple Math] is to prove it analytically. Fortunately, it is quite easy. We can obtain the Taylor series for [Maple Math] at [Maple Math] from the expansion of [Maple Math] at [Maple Math] , which is the geometric series:

[Maple Math] .

To get a series involving powers of [Maple Math] we so some algebraic juggling to rewrite [Maple Math] as follows:

[Maple Math] = [Maple Math] = [Maple Math] = [Maple Math] .

From the uniqueness of power series expansion, the latter series is the Taylor series of [Maple Math] at [Maple Math] . Indeed, it is a power series at [Maple Math] and it converges to [Maple Math] in a neighborhood of [Maple Math] . Hence, it must be the Taylor series of [Maple Math] at [Maple Math] . On the other hand, for any given x, the series is equal to the constant [Maple Math] times the geometric series with ratio [Maple Math] . Hence, the series converges if and only if [Maple Math] , that is when [Maple Math] . Thus, the radius of convergence is indeed [Maple Math] .

Yet another way to see this is to use the formula [Maple Math] with [Maple Math] , as in the text.

Similarly, using the expansion of [Maple Math] , we can easily obtain the Taylor series of [Maple Math] at [Maple Math] :

[Maple Math] ,

whose radius of convergence is [Maple Math] . A conjecture that comes to mind is that the Taylor series at [Maple Math] of any function is convergent in a symmetric interval around [Maple Math] 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 [Maple Math] be a given function, [Maple Math] a given point, [Maple Math] the n-th Taylor polynomial of [Maple Math] at [Maple Math] . Let [Maple Math] be the n-th error. We know an error bound for Taylor approximations. Namely:

[Maple Math] for all x in [ a-d, a+d ] , (EB)

where [Maple Math] is such a constant that

[Maple Math] for all x in [ a-d, a+d ] .

[Maple Math] 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 [Maple Math] . Find the smallest-degree Taylor polynomial at [Maple Math] that stays within 0.1 of the function [Maple Math] 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 [Maple Math] 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);

[Maple Math]

>

> E:=[seq(h(x)-convert(taylor(h(x),x=0,i),polynom),i=2..11)];

[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]

>

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]);

[Maple Plot]

>

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]);

[Maple Plot]

>

The first error function which stays within bounds is E[7]. Hence, the seventh Taylor polynomial is the first that approximates [Maple Math] in [-2,2] within 0.1.

>

Example 4. Let [Maple Math] be as above. Find the thirties Taylor polynomial [Maple Math] of [Maple Math] at x =0. Find the longest interval around zero, [-d,d], such that [Maple Math] stays within 0.01 of [Maple Math] 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 [Maple Math] and label it P30:

> P30:=convert(taylor(h(x),x=0,31),polynom);

[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]

>

Lets define the error of the 30-th degree polynomial:

> E30:=h(x)-P30;

[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]

>

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]);

[Maple Plot]

>

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);

[Maple Math]

[Maple Math]

>

(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 [Maple Math] 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 [Maple Math] for any x is given by:

[Maple Math] .

Hence, to find a polynomial that approximates sin(0.7) as well as we want, we have to find n such that [Maple Math] . In other words, we have to find n such that

[Maple Math] ,

or, equivalently:

[Maple Math] .

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);

[Maple Math]

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);

[Maple Math]

>

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);

[Maple Math]
[Maple Math]
[Maple Math]

>

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);

[Maple Math]

[Maple Math]

>

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 [Maple Math] .

(a) Analytically, that is, "by hand", find the Taylor series of [Maple Math] at x = 0. (You can do it by substituting into the well-known expansion for [Maple Math] 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 [Maple Math] 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 " [Maple Math] " 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: [Maple Math] , 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 [Maple Math] .

(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 [Maple Math] at x = 0. Find the longest interval [-d,d] about x = 0 in which the polynomial stays within 0.1 of [Maple Math] .

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

[Maple Math] .

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.

>