Fourier Series Examples

f(x)=x on [-π,π]

Computation of (Subscript[b, n]):

Simplify[1/π*Integrate[x*Sin[n*x],{x,-π,π}],Assumptions->n∈Integers]

Fourier series approximation:

f[x_,m_]:=Sum[-((2 (((-1))^n))/n)*Sin[n*x],{n,1,m}];

Plot[{x,f[x,10],f[x,20],f[x,50]},{x,-π,π},PlotRange->{-4,4}]

Animate[Plot[{f[x,m],x},{x,-2*π,2*π},PlotRange->{-4,4}],{m,1,100}]

f(x)=x^2 on [-1,1]

Computation of (Subscript[a, 0]):

Simplify[Integrate[x^2,{x,-1,1}],Assumptions->n∈Integers]

Computation of (Subscript[a, n]):

Simplify[Integrate[x^2*Cos[n*π*x],{x,-1,1}],Assumptions->n∈Integers]

Fourier series approximation:

g[x_,m_]:=1/3+Sum[((4 *(((-1))^n))/((n^2) (π^2)))*Cos[n*π*x],{n,1,m}];

Plot[{x^2,g[x,2],g[x,5],g[x,10]},{x,-1,1},PlotRange->{0,1}]

Animate[Plot[{x^2,g[x,m]},{x,-2,2},PlotRange->{0,1}],{m,1,15}]