Module 10 : Series
1005 Taylor Series
O B J E C T I V E
Every function which is infinitely differentiable can be expressed as a Taylor series. In this module, we will examine the definition and create Taylor series from scratch and automatically.We will also investigate convergence, how the number of terms effect the accuracy of the approximation, Taylor polynomials, and Taylor's Remainder Theorem. We will also create an animation to demonstrate how the increasing terms of a Taylors series effect the convergence.
___________________________________________________________________________________
A. Taylor Series and Polynomials
___________________________________________________________________________________
The Taylor Series for a function near a value x = a, is a power series in ( x-a). We will learn how to find Taylor coefficients, how to expand a function iinto a Taylor series using the formula for Taylor series, and how to do it automatically in Maple.
TAYLOR SERIES FROM SCRATCH
The coefficients of a Taylor series expanded about x = a, are f(n) (a)/n!, and each term is of the from f(n) (a)(x-a)^n/n! We can express the coefficient in the following way in Maple.
> restart;
> (D@@n)(f)(a)/n!;
In general, a Taylor series looks like this - except with an infinite number of terms
> sum( (( D@@n)(f)(a) * (x-a)^n)/n!, k = 0..5);
Here is a more concrete example.
> f := x -> 1/(1- 2*x); a:=3;
> (D@@10)(f)(a)/10!;
> sum( (( D@@k)(f)(a) * (x-a)^k )/k!, k=0..5);
This is coefficient for the(x-3)^10 term, and the sum of the first six terms of the Taylor series for this function at this value.
AUTOMATICALLY GENERATING A TAYLOR SERIES
As we have sseen in previous modules, we can use the series command to generate a series for a function. By specifying a particular value of x, the series is expanded about that value. When we saw this before, we were using geometric series possibly along with differentiation and integration to find the series. It turns out that these series expansions are identical to the Taylor series expansions.
> series( 1/(x^2 - 3*x +2 ), x = 0,20);
> series( 1/(x^2 - 3*x +2 ), x = 1,20);
> series( 1/(x^2 - 3*x +2 ), x = 3,20);
Note the series is quite different depending on different expansion values.
CONVERT TO TAYLOR POLYNOMIAL
A Taylor series is an infinite series. Similarly, the n th degree Taylor polynomial is a polynomial of degree n which coincides with the first (n+1) terms of the Taylor series. Tn(x) = c0 + c1(x-a) + c2(x-a)^2 + ... c n(x-a) n . The series created by the Maple command SERIES have an error terms in "big Oh " notation. In various situations it is useful to be able to convert the series with error terms to a Taylor polynomial that can be evaluated and graphed.
> f := x -> 1/(x+3);
> series( f(x), x, 7);
> convert( %, polynom);
> g := unapply( %, x);
> g(1);
Here we define a function f(x), expand it into a series with 7 terms, convert it to polynomial, then use the UNAPPLY command to change the polynomial expression into an actual function, g(x). Finally we evaluate the Taylor polynomial at x =1.
___________________________________________________________________________________
B. Animated Convergence
___________________________________________________________________________________
The Taylor Polynomials gradually converge to the Taylor Serires which is a representation of the original function in some interval of convergence. In this section, we'll see with our own eyes how this convergence takes place in an animation.
First we define a function and a generic Taylor polynomial. Then we define some constant so that our graph desplays for a =< x =< b, and c =<y =< d.
> restart; with(plots):
Warning, the name changecoords has been redefined
> a := -6: b := 6: c := -3: d:= 4:
> f := x -> sin(x);
> g := (x,k) -> convert(series(f(x), x, k), polynom):
> on := x -> piecewise( x <0, 0, x < 1, 1,1);
> display( plot( f(x), x = a..b, y = c..d, thickness = 3, color = blue), animate( on(t-1)*g(x,2) , x = a..b, t = 0..7, view = c..d, color = cyan), animate( on(t-2)*g(x,4) , x = a..b, t = 0..7, view = c..d, color = coral),animate( on(t-3)*g(x,6) , x = a..b, t = 0..7, view = c..d, color = green), animate( on(t-4)*g(x,8) , x = a..b, t = 0..7, view = c..d, color = violet), animate( on(t-5)*g(x,10) , x = a..b, t = 0..7, view = c..d, color = red), animate( on(t-6)*g(x,12) , x = a..b, t = 0..7, view = c..d, color = coral) );
Remember to type multiple lines without executing hit return (macintosh) or shift - retrun (windows). When you execute this command , a graph will appear. Click anywhere on the graph so that a black border appears around the graph. You will also notice that several buttons appear on a task bar at the top of you Maple worksheet. Click on the recycle button (two arrows going in a circle) then the play button ( a triangle). This will start the animation running continuously. You will see the Taylor polynomials T1(x), T3(x),...,T11(x) appear. When you have had had enough fun with this animation, click on the stop button(square).
___________________________________________________________________________________
C. Interval of Convergence
___________________________________________________________________________________
As the number of terms in a Taylor's polynomial increase, the polynomial better approximates the original function. Ultimately, the Taylor series will coincide with the function within an interval of convergence.
> restart; with(plots):
Warning, the name changecoords has been redefined
>
tay_plot := proc( F, c1, c2, k1, k2, a, b, eps)
local x1, x2, y1, y2, delta, dely, m, M, A, B, i, n, g1,g2;
n := 100: delta := (b-a)/n: x2 := a:
M := maximize( F(x), {x}, {x=a..b}): m := minimize( F(x), {x},{x=a..b}):
g1 := unapply( convert(series( F(x), x=c1, k1) , polynom), x);
g2 := unapply( convert(series( F(x), x= c2, k2) , polynom), x); for i from 1 to n do
x1 := x2: x2:=x1 + delta:
y1 := evalf( F(x1)): y2 := evalf( F(x2)):
dely := abs( evalf( F(x1)- g2(x1)));
if( dely < eps )
then B||i := polygonplot([[x1, M],[x1,y1],[x2,y2],[x2,M]], color = maroon, style = patchnogrid):
else B||i := polygonplot([[x1, M],[x1,y1],[x2,y2],[x2,M]], color = khaki, style = patchnogrid): fi:
dely := abs( evalf( F(x1) - g1(x1)));
if (dely < eps)
then A||i := polygonplot([[x1, M],[x1,y1],[x2,y2],[x2,m]], color = violet, style = patchnogrid):
else B||i := polygonplot([[x1, M],[x1,y1],[x2,y2],[x2,m]], color = khaki, style = patchnogrid): fi:
od:
display([ plot( F(x), x = a..b, thickness = 4, color = red),
plot( g1(x), x = a..b, y = m..M, thickness = 2, color= blue),
plot( g2(x), x = a..b, y = m..M, thickness = 2, color= green),
seq( A||i, i=1..n), seq( B||i, i=1..n),
plot( [[c1,m],[c1,F(c1)]], x = a..b, color= blue, linestyle = 3),
plot( [[c2,F(c2)],[c2,M]], x = a..b, color= green, linestyle = 3)],
axes = framed );
end:
.....Here is another form.....(delete on or the two)......
> restart; with(plots):
Warning, the name changecoords has been redefined
>
tay_plot := proc( F, c1, c2, k1, k2, a, b, eps)
local x1, x2, y1, y2, delta, m, M, A, B, i, n, g1,g2, CL, png;
n := 100: delta := (b-a)/n: x2 := a: png := 'patchnogrid';
M := maximize( F(x), x=a..b): m := minimize( F(x), x=a..b):
g1 := unapply( convert(series( F(x), x=c1, k1) , polynom), x);
g2 := unapply( convert(series( F(x), x= c2, k2) , polynom), x); for i from 1 to n do
x1 := x2: x2:= x1 + delta: y1 := evalf( F(x1)): y2 := evalf( F(x2)):
if( abs( evalf( F(x1) - g2(x1))) < eps)
then CL := maroon; else CL := khaki; fi:
A||i := polygonplot( [[x1,M],[x1,y1],[x2,y2],[x2,M]], color = CL, style = png):
if( abs( evalf( F(x1) - g1(x1))) < eps)
then CL := navy ; else CL := khaki; fi;
B||i := polygonplot( [[x1,m],[x1,y1],[x2,y2],[x2,m]], color = CL, style = png):
od:
display([ plot( [F(x), g1(x), g2(x)], x = a..b, y = m..M, thickness = [4,2,2], color = [red, coral, green] ),
plot( [[c1,m],[c1,F(c1)],[c2,f(c2)],[c2,M] ],x = a..b, thickness = 3, color = [ coral, green] ),
seq( A||i, i=1..n), seq( B||i, i = 1..n) ], axes = framed );
end:
> f := x -> ln(1+x); c1 := 3; c2 := 3;
> evalf(f(11));
> tay_plot( f, c1, c2, 3, 6, -0.6, 10, .06);
let's compare Taylor poly's of deg of 2 to 4
> f := x -> cos(x);
> tay_plot( f, Pi/2, Pi/2, 3, 5, -2, 5, .1);
>