Preface


This section concerns about first order partial differential equations.

Return to computing page for the first course APMA0330
Return to computing page for the second course APMA0340
Return to Mathematica tutorial for the first course APMA0330
Return to Mathematica tutorial for the second course APMA0340
Return to the main page for the first course APMA0330
Return to the main page for the second course APMA0340
Return to Part VII of the course APMA0340
Introduction to Linear Algebra with Mathematica

Legendre functions


Consider Legendre's equation
(1-x^2)y'' -2xy' + n(n+1) y =0
when n=4. Legendre's equation comes up in many physical situations
involving spherical symmetry. First we set up a series to work with:

y = Sum[c[i] x^i, {i, 0, 6}] + O[x]^7
Out[1]= c[0] + c[1] x + c[2] x^2 + c[3] x^3 + c[4] x^4 + c[5] x^5 + c[6] x^6 + O[x]^7

To see that our input is correct we type

OutputForm[y]//Normal

We are going to insert this series into the differential equation

de = (1 -x^2) D[y, {x,2}] - 2 x D[y,x] + 20 y == 0
Out[2]= (20 c[0] + 2 c[2]) + (18 c[1] + 6 c[3]) x + (14 c[2] + 12 c[4])
x^2 + (8 c[3] + 20 c[5]) x^3 + 30 c[6] x^4 + O[x]^5 == 0
Then we get the coefficients
coeffeqns = LogicalExpand[de]
Out[3]= 20 c[0] + 2 c[2] == 0 && 18 c[1] + 6 c[3] == 0 &&
14 c[2] + 12 c[4] == 0 && 8 c[3] + 20 c[5] == 0 && 30 c[6] == 0
and express through first two c[0] and c[1]:
solvedcoeffs = Solve[ coeffeqns, Table[ c[i], {i,2,12}]]

Solve::svars: Equations may not give solutions for all "solve" variables. >>

Out[4]= {{c[2] -> -10 c[0], c[3] -> -3 c[1], c[4] -> (35 c[0])/3, c[5] -> (6 c[1])/5, c[6] -> 0}}
Put these back into the series expansion.
y = y /. solvedcoeffs
Out[5]= { c[0] + c[1] x -10 c[0] x^2 - 3 c[1] x^3 + (35/3) c[0] x^4 + (6/5) c[1] x^5 + O[x]^7 }
Extract out the two linearly independent solutions
Coefficient[ y, c[0]]
Out[6]= {1 - 10 x^2 + (35 x^4)/3}
Coefficient[ y, c[1]]
Out[7]= {x - 3 x^3 + (6 x^5)/5}
To check our answer, we use Mathematica again because it knows Legendre:
LegendreP[4,x]
Out[8]= 1/8 (3 - 30 x^2 + 35 x^4)
This is different from the polynomial obtained earlier, but only by a constant factor. The constant factor is used to set the normailization for the Legendre polynomials.

Example: solve the IVP:
(4-x^2 )y'[x]+y[x]==0, y[0]==1

Clear[a,n]
a[n_]:=a[n]=((n-2) a[n-2] -a[n-1])/4/n
a[0] = a0
a[1] = -a0/4
TableForm[Table[{n,a[n]},{n,0,5}]]
Out[21]/TableForm=
0 a0
1 -a0/4
2 a0/32
3 -3 a0/128
4 11 a0/2048
5 -31 a0/8192

When we apply the initial condition, we set a0=1 in the general solution.

Now we solve the initial value problem exactly:

Clear[x,y]
exactsol=DSolve[{(4-x^2)y'[x]+y[x]==0,y[0]==1},y[x],x]
Out[63]= {{y[x]-> (2-x)^(1/4)/(2+x)^(1/4) }}
Note that the exact solution is |2-x|^(1/4)/|2+x|^(1/4) with absolute values instead of parenthethis.

formula=Simplify[(2-x)^(1/4)/(2+x)^(1/4)]

Out[64]= (2 - x)^(1/4)/(2 + x)^(1/4)
var=Table[D[y[x],i]/.x->0,{i,1,11}]
????sols=Solve[sysofeqs,vars]
sersol=Series[y[x],{x,0,11}/.sols[[1]]]

Legendre's equation

genform =
Solve[(n + 2)*(n + 1)*a[n + 2] + (-n*(n - 1) - 2 n + k*(k + 1))*
a[n] == 0, a[n + 2]]
Out[8]= {{a[2 + n] -> -(((k + k^2 - n - n^2) a[n])/((1 + n) (2 + n)))}}
Factor[genform[[1, 1, 2]]]
Out[9]= ((-k + n) (1 + k + n) a[n])/((1 + n) (2 + n))
We obtain a formula for a[n] by replacing each occurrence of n in a[n+2] by n-2.
genform[[1, 1, 2]] /. n -> n - 2
Out[10]= -(((2 + k + k^2 - (-2 + n)^2 - n) a[-2 + n])/((-1 + n) n))
a[n_] := -(((2 + k + k^2 - (-2 + n)^2 - n) a[-2 + n])/((-1 + n) n))
DSolve[(1 - x^2)*y''[x] - 2 x y'[x] + k*(k + 1)*y[x] == 0, y[x], x]
Out[12]= {{y[x] -> C[1] LegendreP[k, x] + C[2] LegendreQ[k, x]}}

 

 

  1. Grigoryan, V, Parial Differential Equations, 2010, University of California, Santa Barbara.

 

Return to Mathematica page
Return to the main page (APMA0340)
Return to the Part 1 Matrix Algebra
Return to the Part 2 Linear Systems of Ordinary Differential Equations
Return to the Part 3 Non-linear Systems of Ordinary Differential Equations
Return to the Part 4 Numerical Methods
Return to the Part 5 Fourier Series
Return to the Part 6 Partial Differential Equations
Return to the Part 7 Special Functions