f(x)=|x|

Let's look at f(x)=|x| on -Pi to Pi. Remember, the functions must be periodic with period 2Pi, so what we really consider is the periodic extension f^(x)=|x| from -Pi to Pi, |x-2Pi| from Pi to 3Pi, etc., which is continuous.

Note: For this example, you will want to click once on the plots that you get and drag the little black boxes to increase the size of the graph.

In[52]:=

  part4=Plot[Abs[x+2Pi],{x,-3Pi,-Pi},DisplayFunction->Identity];
  part5=Plot[Abs[x],{x,-Pi,Pi},DisplayFunction->Identity];
  part6=Plot[Abs[x-2Pi],{x,Pi,3Pi},DisplayFunction->Identity];
  absgraph=Show[part4,part5,part6,
  DisplayFunction->$DisplayFunction,AspectRatio->Automatic];

Mathematica does not like to integrate piecewise defined functions so we must break it down. Note that
|x|=x if x>0
-x if x<0

In[53]:=

  Clear[a0,a,b,Sn]
  a0=(1/(2 Pi))(Integrate[-x,{x,-Pi,0}]+Integrate[x,{x,0,Pi}])
  a[n_]:=1/Pi (Integrate[-x u[x,Pi,n],{x,-Pi,0}]+Integrate[x u[x,Pi,n],{x,0,Pi}])
  Table[a[k],{k,1,10}]
  b[n_]:=1/Pi (Integrate[-x v[x,Pi,n],{x,-Pi,0}]+Integrate[x v[x,Pi,n],{x,0,Pi}])
  Table[b[k],{k,1,10}]

Out[53]=

  Pi
  --
  2

Out[54]=

   -4      -4       -4        -4        -4
  {--, 0, ----, 0, -----, 0, -----, 0, -----, 0}
   Pi     9 Pi     25 Pi     49 Pi     81 Pi

Out[55]=

  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

Can you see the pattern?

Can you see the pattern? ...

Let's calculate a few partial sums.

In[56]:=

  Sn=Table[Sum[a[k]u[x,Pi,k],{k,1,n}],{n,1,10}];

Let's see how we did.

Note: For this example, you will want to click once on the plots that you get and drag the little black boxes to increase the size of the graph.

In[57]:=

  sn1=Plot[a0+Sn[[1]],{x,-2 Pi,2 Pi},DisplayFunction->Identity];
  Show[absgraph,sn1,DisplayFunction->$DisplayFunction,
  PlotLabel->FontForm["a0+a1Cos[x]",{"Helvetica-Bold",12}]];

Pretty good, even with only two terms!

In[58]:=

  sn3=Plot[a0+Sn[[3]],{x,-2 Pi,2 Pi},DisplayFunction->Identity];
  Show[absgraph,sn3,PlotLabel->
  FontForm["a0+a1Cos[x]+a2Cos[2x]+a3Cos[3x]",{"Helvetica-Bold",12}]];

In[59]:=

  sn5=Plot[a0+Sn[[5]],{x,-2 Pi,2 Pi},DisplayFunction->Identity];
  Show[absgraph,sn5,PlotLabel->
  FontForm["a0+Sum(k=1 to 5) akCos[kx]",{"Helvetica-Bold",12}]];

In[60]:=

  sn10=Plot[a0+Sn[[10]],{x,-2 Pi,2 Pi},DisplayFunction->Identity];
  Show[absgraph,sn10,PlotLabel->
  FontForm["a0+Sum(k=1 to 10) akCos[kx]",{"Helvetica-Bold",12}]];

Pretty impressive!

Up to Fourier Series Examples