8.7 Taylor Polynomials and Series

Mathematica script by Chris Parrish,
   cparrish@sewanee.edu

Sources and references for some of these problems include
    James Stewart, "Calculus: Concepts and Contexts," Second Edition, Brooks/Cole, 2001
    Deborah Hughes-Hallett, Andrew M. Gleason, et. al., "Calculus," Second Edition, John Wiley & Sons, 1998
    Robert Fraga, ed., "Calculus Problems for a New Century," The Mathematical Association of America, 1993
    
Mathematica manipulations from
    Skeel and Keiper, pages 171-182

Taylor Polynomials

Taylor polynomials in Mathematica

In[68]:=

Series[Sqrt[1+h],{h,0,4}]

Out[68]=

1 + h/2 - h^2/8 + h^3/16 - (5 h^4)/128 + O[h]^5

In[69]:=

s = Series[Cos[h],{h,0,5}]

Out[69]=

1 - h^2/2 + h^4/24 + O[h]^6

The supporting data structure:

In[70]:=

?SeriesData
FullForm[s]

SeriesData[x, x0, {a0, a1, ... }, nmin, nmax, den] represents a power series in the variable x ... r series. The powers of (x-x0) that appear are nmin/den, (nmin+1)/den, ... , nmax/den. More…

Out[71]//FullForm=

SeriesData[h, 0, List[1, 0, Rational[-1, 2], 0, Rational[1, 24]], 0, 6, 1]

An operation applied to a series results in a series.

In[72]:=

ls = Log[s]

Out[72]=

-h^2/2 - h^4/12 + O[h]^6

Normal will truncate a series.

In[73]:=

diff = Normal[ls] - Log[Cos[h]]

Out[73]=

-h^2/2 - h^4/12 - Log[Cos[h]]

In[74]:=

Plot[diff,{h,-0.2,0.2},
     PlotRange->All,
     PlotStyle->Indigo];

[Graphics:HTMLFiles/8.7.1_taylorPolysAndSeries_7.gif]

Polynomials

CoefficientList

In[75]:=

p = Expand[(1 + 2x + 3y)^3]

Out[75]=

1 + 6 x + 12 x^2 + 8 x^3 + 9 y + 36 x y + 36 x^2 y + 27 y^2 + 54 x y^2 + 27 y^3

In[76]:=

CoefficientList[p,x]

Out[76]=

{1 + 9 y + 27 y^2 + 27 y^3, 6 + 36 y + 54 y^2, 12 + 36 y, 8}

In[77]:=

CoefficientList[p,y]

Out[77]=

{1 + 6 x + 12 x^2 + 8 x^3, 9 + 36 x + 36 x^2, 27 + 54 x, 27}

To go the other way, ...

In[78]:=

{a,b,c,d} . (x^Range[0,3])

Out[78]=

a + b x + c x^2 + d x^3

Examples

Taylor Polynomials

In[79]:=

ln[x_] = Normal[Series[Log[x],{x,1,3}]]

Out[79]=

-1 - 1/2 (-1 + x)^2 + 1/3 (-1 + x)^3 + x

In[80]:=

Plot[{Log[x],ln[x]},{x,0.1,4},
     PlotLabel -> "Taylor Polynomial Approximation",
     PlotStyle -> {{Thickness[0.002],Red},
                   {Thickness[0.004],Green}}];

[Graphics:HTMLFiles/8.7.1_taylorPolysAndSeries_14.gif]

Problems from Hughes-Hallett, Gleason, et al.

Taylor polynomial for Cos[x] near x = 0

Hughes-Hallett, Gleason, et al, First Edition, Exercise 10.1.1, page 598

In[81]:=

Clear[f,taylor,x,x0,a,b,n]

x0 = 0;
n = 4;

f[x_] := Cos[x]

taylor[x_] = Normal[Series[f[x],{x,x0,n}]]

Out[85]=

1 - x^2/2 + x^4/24

In[86]:=

a = -4;
b = 4;

Plot[{f[x],taylor[x]},{x,a,b},
     PlotLabel -> "Taylor Polynomial Approximation",
     PlotStyle -> {{Thickness[0.002],Red},
                   {Thickness[0.004],Green}}];

[Graphics:HTMLFiles/8.7.1_taylorPolysAndSeries_16.gif]

Taylor polynomial for (1 - x)^(1/3) near x=0

Hughes-Hallett, Gleason, et al, First Edition, Exercise 10.1.8, page 598

In[89]:=

Clear[f, taylor, x, x0, a, b, n] <br /> x0 = 0 ; n = 4 ; <br /> f[x_] := (1 - x)^(1/3) <br /> taylor[x_] = Normal[Series[f[x], {x, x0, n}]]

Out[93]=

1 - x/3 - x^2/9 - (5 x^3)/81 - (10 x^4)/243

In[94]:=

a = 0.0;
b = 0.999;

Plot[{f[x],taylor[x]},{x,a,b},
     PlotLabel -> "Taylor Polynomial Approximation",
     PlotStyle -> {{Thickness[0.002],Red},
                   {Thickness[0.004],Green}}];

[Graphics:HTMLFiles/8.7.1_taylorPolysAndSeries_20.gif]

Taylor polynomial for Cos[x] near x = π/2

Hughes-Hallett, Gleason, et al, First Edition, Exercise 10.1.13, page 598

In[97]:=

Clear[f, taylor, x, x0, a, b, n] <br /> x0 = π/2 ; n = 4 ; <br /> f[x_] := Cos[x] <br /> taylor[x_] = Normal[Series[f[x], {x, x0, n}]]

Out[101]=

π/2 - x + 1/6 (-π/2 + x)^3

In[102]:=

a = -4;
b = 4;

Plot[{f[x],taylor[x]},{x,a,b},
     PlotLabel -> "Taylor Polynomial Approximation",
     PlotStyle -> {{Thickness[0.002],Red},
                   {Thickness[0.004],Green}}];

[Graphics:HTMLFiles/8.7.1_taylorPolysAndSeries_23.gif]

Taylor polynomial for Exp[x^2] near x=0

Hughes-Hallett, Gleason, et al, First Edition, Exercise 10.1.34, page 598

In[105]:=

Clear[f, taylor, x, x0, a, b, n] <br /> x0 = 0 ; n = 6 ;  f[x_] := Exp[x^2]  taylor[x_] = Normal[Series[f[x], {x, x0, n}]]

Out[109]=

1 + x^2 + x^4/2 + x^6/6

In[110]:=

a = -2;
b = 2;

Plot[{f[x],taylor[x]},{x,a,b},
     PlotLabel -> "Taylor Polynomial Approximation",
     PlotStyle -> {{Thickness[0.002],Red},
                   {Thickness[0.004],Green}}];

[Graphics:HTMLFiles/8.7.1_taylorPolysAndSeries_27.gif]

In[113]:=

Clear[g,taylor,x,x0,a,b,n]

x0 = 0;
n = 3;

g[x_] := Exp[x]

taylor[x_] = Normal[Series[g[x],{x,x0,n}]]

Out[117]=

1 + x + x^2/2 + x^3/6

In[118]:=

taylor[x^2]

Out[118]=

1 + x^2 + x^4/2 + x^6/6

Conclusion:   taylor[Exp[x^2]] == taylor[Exp[x]] evaluated at x^2


Created by Mathematica  (May 5, 2004)