# Preface

This section concerns about first order partial differential equations.

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

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

Out= {{c -> -10 c, c -> -3 c, c -> (35 c)/3, c -> (6 c)/5, c -> 0}}
Put these back into the series expansion.
y = y /. solvedcoeffs
Out= { c + c x -10 c x^2 - 3 c x^3 + (35/3) c x^4 + (6/5) c x^5 + O[x]^7 }
Extract out the two linearly independent solutions
Coefficient[ y, c]
Out= {1 - 10 x^2 + (35 x^4)/3}
Coefficient[ y, c]
Out= {x - 3 x^3 + (6 x^5)/5}
To check our answer, we use Mathematica again because it knows Legendre:
LegendreP[4,x]
Out= 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==1

Clear[a,n]
a[n_]:=a[n]=((n-2) a[n-2] -a[n-1])/4/n
a = a0
a = -a0/4
TableForm[Table[{n,a[n]},{n,0,5}]]
Out/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==1},y[x],x]
Out= {{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= (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[]]

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= {{a[2 + n] -> -(((k + k^2 - n - n^2) a[n])/((1 + n) (2 + n)))}}
Factor[genform[[1, 1, 2]]]
Out= ((-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= -(((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= {{y[x] -> C LegendreP[k, x] + C LegendreQ[k, x]}}

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