Example 1Recall that

This converges to f(x) where f(x) is continuous and converges to
1/2 [f(x+)+f(x-)] where f(x) has a jump discontinuity.
Remember, with Legendre polynomials p(x)=1, the eigenfunctions are the Legendre polynomials, and the limits of integration are -1 and 1.
Recall from what we saw above that the denominator in the expression for cn is 2/(2n+1).
In[15]:=
f[x_]:=Cos[Pi x/2]
In[16]:=
fplot=Plot[f[x],{x,-3,3}];

In[17]:=
Clear[c0,c,Sn]
c0=1/2 Integrate[f[x]LegendreP[0,x],{x,-1,1}];
Simplify[c0]
c=Table[(2k+1)/2 Integrate[f[x]LegendreP[k,x],{x,-1,1}],{k,1,6}];
Simplify[c]
Out[17]=
2 -- Pi
Out[18]=
2 2 4
10 (-12 + Pi ) 18 (1680 - 180 Pi + Pi )
{0, --------------, 0, -------------------------, 0,
3 5
Pi Pi
2 4 6
26 (-665280 + 75600 Pi - 840 Pi + Pi )
----------------------------------------}
7
Pi
Why all the zeroes at odd k?
Why all the zeroes at odd k? ...
In[19]:=
Sn=Table[c0 LegendreP[0,x]+Sum[c[[k]]LegendreP[k,x],{k,1,n}],{n,1,6}];
Let's see how we did.
In[20]:=
sn1=Plot[Sn[[1]],{x,-3,3},DisplayFunction->Identity];
Show[fplot,sn1,DisplayFunction->$DisplayFunction,
PlotLabel->FontForm["c0P0+c1P1",{"Helvetica-Bold",12}]];

In[21]:=
sn3=Plot[Sn[[3]],{x,-3,3},DisplayFunction->Identity];
Show[fplot,sn3,PlotLabel->
FontForm["c0P0+c1P1+c2P2+c3P3",{"Helvetica-Bold",12}]];

In[22]:=
sn6=Plot[Sn[[6]],{x,-3,3},DisplayFunction->Identity];
Show[fplot,sn6, PlotLabel->
FontForm["Sum(n=0 to 6) cnPn",{"Helvetica-Bold",12}]];

Up to Legendre Polynomials