Legendre Polynomial Series

SetOptions[Plot,AxesLabel->Automatic,PlotStyle->Thick,ImageSize->750,PlotRange->{-1,1.5},BaseStyle->{FontSize->16}];
SetOptions[Manipulate,BaseStyle->{FontSize->20}];
SetOptions[Manipulator,Appearance->{"Labeled"},BaseStyle->{FontSize->20}];

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), or, in Dirac notation: |f>=(∑_( l =0)^∞)|l><l|f>, where (Subscript[P, l])(z)=|l> and (Subscript[c, l])=<l|f>.

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

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

Let's see how much the first few orders of Legendre polynomial (orange) look like f(z) (blue).

Manipulate[
Grid[{
{Plot[{f,LegendreP[l,z]},{z,-1.5,1.5}]},
{},
{StringForm["(Subscript[P, ``])(z)=",l][ LegendreP[l,z]]}},Alignment->Left],
{l,0,10,1}]

1) Which orders do you think will be most prominent in the Legendre series for the epsilon function?

Now, let’s plot f(z)(Subscript[P, l])(z) (red) against the above plot. If we integrate f(z)(Subscript[P, l])(z) from -1 to 1 and multiply by ((2l+1)/2), we get the (l^th) coefficient of the Legendre series for our function; (Subscript[c, l]) = ((2l+1)/2)(∫_(-1)^1)f(z)(Subscript[P, l])(z)dz.

Manipulate[
Grid[{
{StringForm["(Subscript[P, ``])(z)=",l][ LegendreP[l,z]]},
{},
{Show[{Plot[{f,LegendreP[l,z]},{z,-1,1}],Plot[{"","","",f LegendreP[l,z]},{z,-1,1},Filling->Axis]}]},
{},
{ToString[l+1/2,TraditionalForm]StringForm["* area between f(z)(Subscript[P, ``])(z)and z axis for |z|≤1: ",l][Integrate[(2l+1)/2f LegendreP[l,z],{z,-1,1}]]}},Alignment->Left],
{l,0,10,1}]

2) Compare the Legendre coefficient integral to the Fourier coefficient integrals ((Subscript[a, n])=(1/π)(∫_(-π)^π)f(x)cos(n x)dx and (Subscript[b, n])=(1/π)(∫_(-π)^π)f(x)sin(n x)dx).

3) Why do we often refer to inner products as “overlap integrals?”

Finally, let's calculate the first few coefficients of the Legendre polynomial series and plot the series (orange) against f(z) (blue).

Manipulate[
LegCoeffTable=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}];
r=Sum[c[m]*LegendreP[m,z],{m,0,lmax}];
Grid[{
{Plot[{f,r},{z,-1.5,1.5}]},
{},
{"Legendre Coefficients:"[LegCoeffTable]},
{},
{"Expanded Legendre Series:"[r]},
{},
{"Simplified Legendre Series:"[Simplify[r]]}},Alignment->Left],
{lmax,0,10,1}]

4) Write the Legendre series in terms of the Legendre coefficients and their respective (Subscript[P, l])(z)’s, explicitly including terms with coefficients of zero; (Subscript[c, 0])(Subscript[P, 0])(z)+(Subscript[c, 1])(Subscript[P, 1])(z)+(Subscript[c, 2])(Subscript[P, 2])(z)+...

5) What are the advantages and limitations of using a Legendre series to approximate a function?