Reza Malek-Madani

Fourier Cosine Series

Here is how one finds the Fourier Cosine series of the function f(x) = x, with x in the interval (0, 2), and plots its partial sums.

l=2; (* The domain *) 
nn= 20; (* Partial Sum *) 
f[x_] =x ; (* Function Definition *) 
a[n_]:=Integrate[f[x]Cos[n Pi x/l], {x, 0, l}]; 
coeffs = Table[a[n], {n, 0, nn}]; 
S[n_, x_]:=coeffs[[1]]/l+Sum[2 coeffs[[i+1]]/l Cos[i Pi x/l], {i, 1, n}]; 
graph1=Plot[f[x], {x, 0, l}]; 
snapshots[i_]:=Plot[S[i,x], {x, 0, l}, DisplayFunction->Identity]; 
Do[ii=ToString[i]; 
        llabel=StringJoin["The function and its ",ii,"-th partial sum"]; 
       Show[graph1,snapshots[i], PlotLabel->llabel, 
       DisplayFunction->$DisplayFunction, PlotRange->All], 
{i, 5, nn, 5}] 
[Graphics:fourier2gr2.gif][Graphics:fourier2gr1.gif][Graphics:fourier2gr2.gif][Graphics:fourier2gr3.gif][Graphics:fourier2gr2.gif][Graphics:fourier2gr4.gif][Graphics:fourier2gr2.gif][Graphics:fourier2gr5.gif][Graphics:fourier2gr2.gif][Graphics:fourier2gr6.gif]

go to Top