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]=
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]=
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]=
The term Orepresentes 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]=
Apply the FullSimplify function to simplify all of the coefficients in sersoln displayed above.
In[42]:=
FullSimplify[sersoln]
Out[42]=
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]=
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]=
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}}]
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}] ] ]
In[77]:=
Show[ Plot[ BesselY[0,x], {x,0,20} ],
Plot[ BesselY[1,x], {x,0,20}, PlotStyle->Dashing[{0.02,0.02}] ] ]
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)