SetDirectory[$HomeDirectory<>"/Documents/handouts/math467/FourierIntro"]

PeriodicExtension[f_,L_][x_]:=f[Mod[x,2L,-L]]

EvenExtension[f_,L_][x_]:=PeriodicExtension[Piecewise[{{f[#],0≤#≤L},{f[-#],-L≤#≤0}}]&,L][x]

OddExtension[f_,L_][x_]:=PeriodicExtension[Piecewise[{{f[#],0≤#≤L},{-f[-#],-L≤#≤0}}]&,L][x]

Example 01

g[x_]:=(x^2)

Plot[g[x],{x,-1,1},AxesLabel->{"x","y"},PlotRange->{{-3,3},Automatic}]

Export["example01.pdf",%,"PDF"]

Export["example01.eps",%%,"EPS"]

Plot[PeriodicExtension[g,1][x],{x,-3,3},AxesLabel->{"x","y"},PlotRange->{{-3,3},Automatic}]

Export["example01ext.pdf",%,"PDF"]

Export["example01ext.eps",%%,"EPS"]

Example 02

g[x_]:=Exp[x]

Plot[g[x],{x,-1,1},AxesLabel->{"x","y"},PlotRange->{{-3,3},Automatic}]

Export["example02.pdf",%,"PDF"]

Export["example02.eps",%%,"EPS"]

Plot[PeriodicExtension[g,1][x],{x,-3,3},AxesLabel->{"x","y"},PlotRange->{{-3,3},Automatic}]

Export["example02ext.pdf",%,"PDF"]

Export["example02ext.eps",%%,"EPS"]

Example 03

f[x_]:=Piecewise[{{x,-1≤x≤0},{0,0≤x≤1}}]

Integrate[f[x],{x,-1,1}]

Integrate[f[x]Cos[n π x],{x,-1,1},Assumptions->{n∈Integers}]

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

Plot[PeriodicExtension[f,1][x],{x,-3,3},PlotRange->{-1,1},AxesLabel->{"x","f(x)"}]

Export["example03ext.pdf",%,"PDF"]

Export["example03ext.eps",%%,"EPS"]

fsim[n_][x_]:=-(1/4)+Sum[(((-1))^(k+1))/(k π)Sin[k π x],{k,1,n}]+Sum[2/((((2k-1))^2)(π^2))Cos[(2k-1)π x],{k,1,n}]

Plot[{PeriodicExtension[f,1][x],fsim[10][x]},{x,-3,3},PlotRange->{-1,1},AxesLabel->{"x","y"}]

Export["example03fs.pdf",%,"PDF"]

Export["example03fs.eps",%%,"EPS"]

Example 04

f[x_]:=(x^2)

Integrate[f[x],{x,-π,π}]/π

Integrate[f[x]Cos[n x],{x,-π,π},Assumptions->{n∈Integers}]/π

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

Plot[PeriodicExtension[f,π][x],{x,-3π,3π},Ticks->{Table[n π,{n,-3,3,1}],Automatic},AxesLabel->{"x","f(x)"}]

Export["example04ext.pdf",%,"PDF"]

Export["example04ext.eps",%%,"EPS"]

fsim[n_][x_]:=(π^2)/3+Sum[4(((-1))^k)/(k^2)Cos[k x],{k,1,n}]

Plot[{PeriodicExtension[f,π][x],fsim[10][x]},{x,-3π,3π},AxesLabel->{"x","y"},Ticks->{Table[n π,{n,-3,3,1}],Automatic}]

Export["example04fs.pdf",%,"PDF"]

Export["example04fs.eps",%%,"EPS"]

Example 05

f[x_]:=Piecewise[{{0,-π≤x≤0},{Sin[x],0≤x≤π}}]

Integrate[f[x],{x,-π,π}]/π

Integrate[f[x]Cos[n x],{x,-π,π},Assumptions->{n∈Integers}]/π

Integrate[f[x]Sin[x],{x,-π,π}]/π

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

Plot[PeriodicExtension[f,π][x],{x,-3π,3π},Ticks->{Table[n π,{n,-3,3,1}],Automatic},AxesLabel->{"x","f(x)"},PlotRange->{-1,1}]

Export["example05ext.pdf",%,"PDF"]

Export["example05ext.eps",%%,"EPS"]

fsim[n_][x_]:=1/π+Sin[x]/2-Sum[2Cos[2k x]/(π(4(k^2)-1)),{k,1,n}]

Plot[{PeriodicExtension[f,π][x],fsim[10][x]},{x,-3π,3π},AxesLabel->{"x","y"},Ticks->{Table[n π,{n,-3,3,1}],Automatic},PlotRange->{-1,1}]

Export["example05fs.pdf",%,"PDF"]

Export["example05fs.eps",%%,"EPS"]

Example 06

f[x_]:=Abs[Sin[x]]

fsim[n_][x_]:=2/π-Sum[4Cos[2k x]/(π(4(k^2)-1)),{k,1,n}]

Plot[{PeriodicExtension[f,π][x],fsim[10][x]},{x,-3π,3π},AxesLabel->{"x","y"},Ticks->{Table[n π,{n,-3,3,1}],Automatic},PlotRange->{-1,1}]

Export["example06fs.pdf",%,"PDF"]

Export["example06fs.eps",%%,"EPS"]

Example 07

f[x_]:=Cos[x]

Plot[OddExtension[f,π/2][x],{x,-2π,2π},PlotPoints->40,AxesLabel->{"x","(Subscript[f, o])(x)"},Ticks->{Table[k π,{k,-2,2,1/2}],Automatic}]

Export["example07odd.pdf",%,"PDF"]

Export["example07odd.eps",%%,"EPS"]

4Integrate[Cos[x]Sin[n π x/(π/2)],{x,0,π/2},Assumptions->{n∈Integers}]/π

fsim[n_][x_]:=Sum[8k/((4(k^2)-1)π)Sin[2k x],{k,1,n}]

Plot[{OddExtension[f,π/2][x],fsim[10][x]},{x,-2π,2π},PlotPoints->40,AxesLabel->{"x","y"},Ticks->{Table[k π,{k,-2,2,1/2}],Automatic}]

Export["example07fs.pdf",%,"PDF"]

Export["example07fs.eps",%%,"EPS"]

Example 08

f[x_]:=Exp[x]

Plot[EvenExtension[f,1][x],{x,-3,3},AxesLabel->{"x","(Subscript[f, e])(x)"},PlotRange->{0,E}]

Export["example08even.pdf",%,"PDF"]

Export["example07even.eps",%%,"EPS"]

2Integrate[Exp[x],{x,0,1}]

2Integrate[Exp[x]Cos[n π x],{x,0,1},Assumptions->{n∈Integers}]

fsim[n_][x_]:=E-1+Sum[2 ((((-1))^k)E-1)/((k^2)(π^2)+1)Cos[k π x],{k,1,n}]

Plot[{EvenExtension[f,1][x],fsim[10][x]},{x,-3,3},AxesLabel->{"x","y"},PlotRange->{0,E}]

Export["example08fs.pdf",%,"PDF"]

Export["example08fs.eps",%%,"EPS"]