Fourier series

Orthogonality of trigonometric functions

Clear[m,n];

FullSimplify[Integrate[Cos[m x]Sin[n x],{x,0,2 Pi}],And[m∈Integers,n∈Integers]]

FullSimplify[Integrate[Cos[m x]Cos[m x],{x,0,2 Pi}],And[m∈Integers]]

FullSimplify[Integrate[Cos[m x]Cos[n x],{x,0,2 Pi}],And[m∈Integers]]

FullSimplify[Integrate[Sin[m x]Sin[n x],{x,0,2 Pi}],And[m∈Integers]]

My names

Clear[MyTrig];

MyTrig[m_,x_]:=If[EvenQ[m],Sin[(m/2)x],Cos[((m-1)/2)x]]

Table[MyTrig[k,x],{k,1,20}]

Table[Table[Integrate[MyTrig[m,x] MyTrig[n,x],{x,0,2 Pi}],{m,1,10}],{n,1,10}]//MatrixForm

Clear[MyTrigN];

MyTrigN[m_,x_]:=
  If[m==1,(1/(Sqrt[2 Pi])),(1/(Sqrt[Pi]))MyTrig[m,x]
]

Table[Table[Integrate[MyTrigN[m,x] MyTrigN[n,x],{x,0,2 Pi}],{m,1,20}],{n,1,20}]//MatrixForm

Example 1

Clear[ff,x];

ff[x_]=x;

coT=Table[(Integrate[ff[t] MyTrigN[m,t],{t,0,2 Pi}]),{m,1,30}]

Plot[{ff[x]},{x,0,2 π},PlotRange->{{-0.2`,2 π+0.2`},{-0.2`,2 π+0.2`}},PlotStyle->{{RGBColor[0,0,0],Thickness[0.01`]},{RGBColor[1,0,0],Thickness[0.006`]}},AspectRatio->Automatic,Ticks->{Range[-π,3 π,(π/2)],Range[-π,3 π,(π/2)]}]

Clear[Fs,x,k];

Fs[x_,k_]:=Sum[coT[[j]] MyTrigN[j,x],{j,1,k}];

Table[Plot[{ff[x],Fs[x,j]},{x,0,2  Pi},PlotRange->{{-.2,2 Pi+0.2},{-.2,2 Pi+0.2}},PlotStyle->{{RGBColor[0,0,0],Thickness[0.01]},{RGBColor[1,0,0],Thickness[0.006]}},AspectRatio->Automatic,Ticks->{Range[-Pi,3 Pi,(Pi/2)],Range[-Pi,3 Pi,(Pi/2)]}],{j,1,14}]

Table[Fs[x,k],{k,1,10}]//TableForm

Example 2

Clear[ff,x];

ff[x_]=(1/Pi)x (2 Pi-x);

coT=Table[(Integrate[ff[t] MyTrigN[m,t],{t,0,2 Pi}]),{m,0,25}]

Plot[{ff[x]},{x,0,2 π},PlotRange->{{-0.2`,2 π+0.2`},{-0.2`,π+0.2`}},PlotStyle->{{RGBColor[0,0,0],Thickness[0.01`]},{RGBColor[1,0,0],Thickness[0.006`]}},AspectRatio->Automatic,Ticks->{Range[-π,3 π,(π/2)],Range[-π,3 π,(π/2)]}]

Clear[Fs,x,k];

Fs[x_,k_]:=Sum[coT[[j+1]] MyTrigN[j,x],{j,0,k}];
Table[Plot[{ff[x],Fs[x,j]},{x,0,2  Pi},PlotRange->{{-.2,2 Pi+0.2},{-.2, Pi+0.2}},PlotStyle->{{RGBColor[0,0,0],Thickness[0.01]},{RGBColor[1,0,0],Thickness[0.006]}},AspectRatio->Automatic,Ticks->{Range[-Pi,3 Pi,(Pi/2)],Range[-Pi,3 Pi,(Pi/2)]}],{j,1,14}]

Table[Fs[x,k],{k,1,10}]//TableForm

Example 3

Clear[ff,x];

ff[x_]=(1/(Pi^2))(x^2) (2 Pi-x);

Plot[{ff[x]},{x,0,2 π},PlotRange->{{-0.2`,2 π+0.2`},{-0.2`,π+1.2`}},PlotStyle->{{RGBColor[0,0,0],Thickness[0.01`]},{RGBColor[1,0,0],Thickness[0.006`]}},AspectRatio->Automatic,Ticks->{Range[-π,3 π,(π/2)],Automatic}]

coT=Table[(Integrate[ff[t] MyTrigN[m,t],{t,0,2 Pi}]),{m,0,25}]

Clear[Fs,x,k];

Fs[x_,k_]:=Sum[coT[[j+1]] MyTrigN[j,x],{j,0,k}];

Table[Plot[{ff[x],Fs[x,j]},{x,0,2  Pi},PlotRange->{{-.2,2 Pi+0.2},{-.2, Pi+1.2}},PlotStyle->{{RGBColor[0,0,0],Thickness[0.01]},{RGBColor[1,0,0],Thickness[0.006]}},AspectRatio->Automatic,Ticks->{Range[-Pi,3 Pi,(Pi/2)],Automatic}],{j,1,24}]

Table[Fs[x,k],{k,1,10}]//TableForm

Example 4

Clear[ff,x];

ff[x_]=Pi-Abs[x-Pi];

coT=Table[(Integrate[ff[t] MyTrigN[m,t],{t,0,2 Pi}]),{m,0,25}]

Clear[Fs,x,k];

Fs[x_,k_]:=Sum[coT[[j+1]] MyTrigN[j,x],{j,0,k}];

Table[Plot[{ff[x],Fs[x,j]},{x,0,2  Pi},PlotRange->{{-.2,2 Pi+0.2},{-.2, Pi+1.2}},PlotStyle->{{RGBColor[0,0,0],Thickness[0.01]},{RGBColor[1,0,0],Thickness[0.006]}},AspectRatio->Automatic,Ticks->{Range[-Pi,3 Pi,(Pi/2)],Range[-Pi,3 Pi,(Pi/2)]}],{j,1,24}];