Fourier Series of Simple Functions

Manipulate[
Plot[{PeriodicExtension[k[[1]],x],Evaluate[k[[2]]+Sum[k[[3]] Sin[n x]+k[[4]] Cos[n x],{n,1,m}]]},{x,-r,r},Axes->{True,True}, PlotStyle->{{Thickness[0.003],Black},{Thickness[0.003],Blue}} ,
              Filling->{1->{{2},{Yellow,Orange}}},ImageSize->{500,400},ImagePadding->30],{{k,{Sign,0,1/(Pi*n)*(1-2Cos[n*Pi]+1),0},"function"},{{Sign,0,1/(Pi*n)*(2-2Cos[n*Pi]),0}->"step",{#&,0,2(-1)^(n+1)/n,0}->"sawtooth",
{#^2&,((π^2)/3),0,((4 (((-1))^n))/(n^2))}->"parabola",
{(#-Pi )(#+Pi)(#-1)&,((2 (π^2))/3),((12 (((-1))^n))/(n^3)),-(( 4(((-1))^n))/(n^2))}->"cubic",
{(Sin[#]UnitStep[#])&,1/Pi,KroneckerDelta[n,1]/2,If[n==1,0,(-((1+(((-1))^n))/((-1+(n^2)) π)))]}->"half-wave rectifier"}},
{{m,3,"number of terms"},1,50,1,Appearance->"Labeled"},{{r,Pi,"x range"},Pi,5*Pi,Pi,Appearance->"Labeled"},Initialization:>{(PeriodicExtension[g_,x_]:=If[Abs[x]<Pi,g[x],PeriodicExtension[g,x-2Sign[x]Pi]])}]

THIS NOTEBOOK IS THE SOURCE CODE FROM

"Fourier Series of Simple Functions" from The Wolfram Demonstrations Project
 http://demonstrations.wolfram.com/FourierSeriesOfSimpleFunctions/

Contributed by: Alain Goriely

A full-function Wolfram Mathematica 6 system is required to edit this notebook.
GET WOLFRAM MATHEMATICA 6 »

© The Wolfram Demonstrations Project & Contributors   |   Terms of Use   |   Make a new version of this Demonstration »