Math 421  •  Fall 2006

Taylor series

Copyright © 2004–2006 by Murray Eisenberg.  All rights reserved.

This notebook shows how to use Mathematica to obtain representations of power series for complex functions.

Initializations

Load David Park's Cardano3 application packages.

Needs["Cardano3`ComplexGraphics`"]
Needs["Cardano3`ComplexRoutines`"]

Turn off some annoying warning messages that might otherwise appear about similarly-named objects.  (If you want to see these messages so as to be sure to avoid harm, evaluate expressions like the ones below but replace Off there by On.)

Off[General::spell]
Off[General::spell1]

Taylor series: the Mathematica function Series

?Series

Series[Exp[z],  {z,  0,  6}]

The term O[z]^7 in the preceding result means that the remainder of the infinitely many terms in the power series consists of terms of the form (Subscript[c, k]) (z^k) with k  ≥  7.  Thus the result provides the usual Taylor polynomial + Taylor remainder form Exp(z)  =  (Subscript[P, 7])(z)  +  (Subscript[R, 7])(z) but with an indication of only the order of the terms in the remainder and not their actual coefficients.

The result of Series displays as shown, but what the result actually is a Mathematica SeriesData object:

Head[Series[Exp[z],  {z,  0,  6}]]
FullForm[Series[Exp[z],  {z,  0,  6}]]

The situation for such a SeriesData object is similar to that for a Graphics object (such as might result from a Plot or ComplexGraphics expression): just as Graphics expression returns a Graphics object but causes a display of graphics, so a Series expression returns a SeriesData object but causes a display that includes an O[z]^n expression.

To a certain extent, you can manipulate such SeriesData objects as if they were actually the value of the entire infinite series.  For example:

1  +  2 Series[Exp[z],  {z,  0,  6}]

However, the result of Series is not a function of a complex variable, in the ordinary mathematical sense, as the output from the following two input cells show:

f[z_]  :=  Series[Exp[z],  {z,  0,  6}]

f[0]

By means of a substitution rule you can also obtain the value at the center (here, 0) of the series expansion…

f[z]  /.  z  ->  0

…but usually not elsewhere:

f[z]  /.  z  ->  1

You can manipulate the variable z so as to replace it with another variable, though:

f[z]  /.  z  ->  t

There's no restriction against expanding about points other than the origin.  For example:

Series[Exp[z],  {z,  1,  10}]

Such centers other than 0 are more common for functions other than the exponential function.  For example:

Series[Log[z],  {z,  1,  5}]

Mathematica finds Taylor series expansions essentially the way you would, by taking derivatives of the function at the center and dividing by suitable factorials, etc.  When you don't provide an explicit formula for the first argument to Series (or when Mathematica cannot determine what the derivatives are), Mathematica can still provide an indication of the form of the Taylor series.  For example:

Clear[g]
Series[g[z],  {z,  0,  5}]

Since Mathematica understands the form of a Taylor series, you can do things like the following:

F[z_]  :=  Series[Log[z],  {z,  1,  5}]

F'[z]

For what function is that the Taylor series?  (Hint: The answer is the same as in the case of a real variable.)

Taylor polynomials: the Normal form of a Series expression

To obtain just the sum of the first n terms of a Taylor series—in other words, the nth order Taylor polynomial—wrap the Series expression with the function Normal.  For example:

Series[Exp[z],  {z,  0,  6}]

Normal[ Series[Exp[z],  {z,  0,  6}] ]

The same thing:

Series[Exp[z],  {z,  0,  6}]  //  Normal

What sort of an object is the result of a Normal[Series[…]] expression?

Head[ Normal[ Series[Exp[z],  {z,  0,  6}] ]  ]
FullForm[ Normal[ Series[Exp[z],  {z,  0,  6}] ]  ]

Using a Taylor polynomial as a function

The last output of the preceding section looks like a polynomial function of the variable.  So surely you should be able to evaluate a Normal[Series[…] expression at various inputs?  Try it:

p6[z_]  :=  
      Normal[ Series[Exp[z],  {z,  0,  6}] ]
p6[1]

Well, that doesn't work!  The difficulty is that z must be a variable in order for the inside Series expression to be evaluated correctly.  (It's somewhat analogous to the situation of trying to replace the "dummy variable" x in (∫_0^1) (x^2) dx with, say, 5 before evaluating the integral.)

Here are two methods for using the result of a Normal[Series[…]] expression as a function.

Method 1:  Use a substitution rule:

poly6  =  Normal[ Series[Exp[z],  {z,  0,  6}] ]

poly6  /.  z  ->  1

poly6  /.  z  ->  1.

Method 2:   Use an = (Set) definition instead of the more usual := (SetDelayed) definition:

Clear[P6]
P6[z_]  =  Normal[ Series[Exp[z],  {z,  0,  6}] ]

P6[1. ]

Extracting the coefficients

?CoefficientList

Use the function CoefficientList to obtain the list of coefficients of a Taylor polynomial.  (You must specify as a second argument to CoefficientList the variable of whose powers you want the coefficients.)

CoefficientList[ Normal[ Series[Exp[z],  {z,  0,  6}] ],  
      z ]

This works also for the function form of the Taylor polynomial:

Clear[P6]
P6[z_]  =  
        Normal[ Series[
            Exp[z],  {z,  0,  6}] ];
CoefficientList[P6[z],  z]

And it also works for a Series expression for the Taylor series as well:

CoefficientList[ Series[Exp[z],  {z,  0,  6}],  z ]

To obtain a particular coefficient or coefficients, just select from the list of coefficients using any of the usual ways.  For example:

c  =  
        CoefficientList[ Series[Exp[z],  {z,  0,  6}],  
          z ];
c[[1]]
First[c]
Last[c]

⚠ Caution:  The list resulting from a CoefficientList expression is an ordinary list, whose entries are indexed by 1, 2, 3. ….  So the first entry of that list is the coefficient of the term of the Taylor series (or Taylor polynomial) of order 0, that is the constant term.  Thus if you wanted, say, the coefficient of the (z^2) term, you would use…

c[[3]]

…and not c[[2]].

Another way to obtain a particular coefficient is to use the function Coefficient.  For example:

Coefficient[Series[Exp[z],  {z,  0,  6}],  z,  2]

Convergence of Taylor polynomials

To see many successive Taylor polynomials, use Table:

Table[
      Normal[ Series[Exp[z],  {z,  0,  n}] ],  {n,  0,  
        10}]

Then to see convergence of these successive Taylor polynomials—the successive partial sums of the infinite Taylor series—use a substitution rule for the value of z that is of interest:

show15Digits[x_]  :=  NumberForm[x,  15]
show15Digits @ 
      Table[Normal[ Series[Exp[z],  {z,  0,  n}] ]  /.  
          z  ->  1.   +  (1/2) I,  {n,  0,  20}]

To see convergence of the partial sums at a particular value of z to the sum of the infinite series, you may use the Cardano3 application as you saw in the notebook Sequences.nb.  For example:

(Subscript[z, n])_  :=  
      Normal[ Series[Exp[z],  {z,  0,  n}] ]  /.  
        z  ->  1.   +  0.5  I
ComplexGraphics[{Blue,  PointSize[0.01],  
          ComplexPoint  /@  
            Table[(Subscript[z, n]),  {n,  1,  
                100}]},  
PlotRange  ->  {{2.2, 
              2.55},  {0.9,  1.7}},  
        AxesOrigin  ->  {E Cos[(1/2)],  E Sin[(1/2)]},  
        FrameTicks  ->  Automatic,  AspectRatio -> 1, 
        ImageSize -> 8*72];

Notice that the axes in the preceding plot were drawn with respect to an origin at the point:

Exp[1 + (1/2) I]  //  ComplexExpand

Moreover, the convergence of the Taylor polynomials is very rapid.  That's why you only see a few points in the plot.

Exercise.  
	(a) What is the value of the Taylor series expansion of Exp(z) at z  =  i?  (Hint:  Use 1. i to get a numerical value.)
	(b) Create a display that shows the convergence of the Taylor polynomials evaluated at z = i to the sum.