Appendix A1. Power Series and Special Functions
Series Solutions

Mathematica's Series function can be used to obtain a series solution to a differential equation, provided DSolve can solve it in terms of special functions. SeriesCoefficient can generate the nth coefficient in a series expansion.

Example  Obtain a series solution to the following differential equation (Ledder, A4, Exercise 2).

y'' + 2x y' - y = 0

Then obtain the first 6 non-zero terms of the series solution satisfying y(0) = 1, y'(0) = 3. Plot the  approximate and the exact solutions. (Think of a mass spring system with a "repelling" spring moving in a  fluid that is thickening with time.)

First enter and name the ode.

In[2]:=

DE = y''[x] + 2*x*y'[x] - y[x] == 0

Out[2]=

-y[x] + 2 x y^′[x] + y^′′[x] 0

The general solution is in terms of special functions. Note that it is obtained using generic initial values, y(0) = y0 and y'(0) = y1.

In[11]:=

gensoln = DSolve[ {DE, y[0]==y0, y'[0]==y1}, y[x], x ]

Out[11]=

{{y[x]  -1/(3 Gamma[5/4]) (^(-x^2) (4 2/π^(1/2) y1 Gamma[5/4] Gamma[7/4]  ... Gamma[5/4] Hypergeometric1F1[3/4, 1/2, x^2] - 2 y1 Gamma[7/4] Hypergeometric1F1[3/4, 1/2, x^2]))}}

The next entry applies Series to gensoln to generate the first 5 terms in the Taylor series representation for the general solution, expanded about x = 0. The syntax for the nth order Taylor series of an expression in x, expanded about x0, is shown below.

Series[ expression, {x, x0, n} ]

In[28]:=

sersoln = Series[ y[x]/.gensoln[[1]], {x,0,5} ]

Out[28]=

y0 + (4 y1 Gamma[7/4] x)/(3 Gamma[3/4]) + (y0 x^2)/2 - (2 (y1 Gamma[7/4]) x^3)/(9 Gamma[3/4]) - (y0 x^4)/8 + (y1 Gamma[7/4] x^5)/(18 Gamma[3/4]) + O[x]^6

The term O[x]^6representes the error in the approximation.
If you would like to see a particular coefficient, for example the 20th,  first generate the 20th order series and then apply the function SeriesCoefficient.

In[88]:=

Series[y[x]/.gensoln[[1]], {x,0,20}];
SeriesCoefficient[ %, 20]

Out[89]=

-(713 y0)/39105331200

Apply the FullSimplify function to simplify all of the coefficients in sersoln displayed above.

In[42]:=

FullSimplify[sersoln]

Out[42]=

y0 + y1 x + (y0 x^2)/2 - (y1 x^3)/6 - (y0 x^4)/8 + (y1 x^5)/24 + O[x]^6

The Normal function can be used to convert the series solution into a polynomial approximation (i.e. eliminate the error term). When applied to the last output, Normal also collects the terms containing y0 and the ones containing y1.

In[43]:=

Normal[%]

Out[43]=

y0 + (x^2 y0)/2 - (x^4 y0)/8 + x y1 - (x^3 y1)/6 + (x^5 y1)/24

If initial values are given, like y(0) = 1 and y(0) = 3, they can be used in DSolve. To obtain the first 6 Taylor series terms ask for the order 6 series.

In[70]:=

soln = DSolve[ {DE, y[0]==1, y'[0]==3}, y[x], x ];
Series[y[x]/.%[[1]], {x,0,6}];
approxsoln = Normal[FullSimplify[%]]

Out[72]=

1 + 3 x + x^2/2 - x^3/2 - x^4/8 + x^5/8 + (7 x^6)/240

The following picture shows the exact and approximate solution curves. The approximation is the dashed curve.

In[69]:=

Show[ Plot[ y[x]/.soln, {x,0,3} ],
      Plot[ approxsoln, {x,0,3}, PlotStyle->Dashing[{0.02,0.02}]],
      PlotRange->{{0,3},{0,8}}]

[Graphics:HTMLFiles/Math_A1_9.gif]

Special Functions

Mathematica has, built-in, most of the special functions that are found in elementary differential  equations textbooks. For example, the Bessel functions of the first and second kind of order n are denoted  BesselJ[n,x] and BesselY[n,x] respectively. Compare the plots below to the ones appearing in Chapter 3,  Figures 3.7.3 and 3.7.4 in Ledder.

In[76]:=

Show[ Plot[ BesselJ[0,x], {x,0,20} ],
      Plot[ BesselJ[1,x], {x,0,20}, PlotStyle->Dashing[{0.02,0.02}] ] ]

[Graphics:HTMLFiles/Math_A1_10.gif]

In[77]:=

Show[ Plot[ BesselY[0,x], {x,0,20} ],
      Plot[ BesselY[1,x], {x,0,20}, PlotStyle->Dashing[{0.02,0.02}] ] ]

[Graphics:HTMLFiles/Math_A1_11.gif]

To see a list of the functions that are known to Mathematica go the Help Browser and choose

Built-in Functions/Mathematical Functions/(Alphabetical Listing)


Created by Mathematica  (December 9, 2004)