Legendre Polynomial Series

In this worksheet, you will use the Legendre Polynomials to approximate a function in the same way you use sines and cosines or exponentials to approximate a function in Fourier series. 

We want to approximate a function f(z) with Legendre Polynomials (Subscript[P, l])(z), analogously to doing Fourier series, i.e.

							f(z) = (∑_( l =0)^∞)(Subscript[c, l])(Subscript[P, l])(z)

Let's start with the epsilon function f(z) = ϵ(z), where ϵ(z) is the integral of the Heaviside function θ(z).

f= Piecewise[{{0,z<0},{z,z>0}}]

Plot[f,{z,-2,2}]

First let's check how much each Legendre polynomial look like ϵ(z).

l:=0
Plot[{f,LegendreP[l,z]},{z,-2,2}]

Now change the value of l to check some other Legendre polynomials.

Now let's calculate the coefficients of the Legendre polynomial expansion.


						(Subscript[c, l]) = (∫_(-1)^1)((f(2l+1)P(l,z))/2)dz
						

(Compare this expression to the expression for the coefficients in a Fourier series.)

Why is the factor ((2l+1)/2) in the equation?

lmax:=3
Table[Integrate[((2*m+1)/2)*f*LegendreP[m,z],{z,-1,1}],{m,0,lmax}]
Do[c[m]=Integrate[((2*m+1)/2)*f*LegendreP[m,z],{z,-1,1}],{m,0,lmax}]

Let's look at the graph of the truncated series, and compare it to the graph of f(z).

r=Sum[c[m]*LegendreP[m,z],{m,0,lmax}]
Plot[{r,f},{z,-2,2}]

How good a job did the Legendre polynomials do? Try adding more terms. How many terms does it take to get decent convergence?  What happens outside the range -1..1? Why? Compare to the Fourier series approximation to the function.