Fourier Cosine Series

If we use the even periodic extension of f(x), we will be finding the Fourier series of an even function.
Let's make a few notes:
1. All of the bk terms will be zero!
(This is because we have an even function.)
2. Instead of integrating from -L to L to get the ak, we take twice the integral from 0 to L.
(This is because we will always have the integral of f(x)cos(k Pi/L x), which is an even function times an even function, producing an even function.)

a0=(1/L) Integral from 0 to Pi of f(x)
ak=(2/L)
Integral from 0 to L of f(x)cos(k Pi/L x)
bk=0

Let's do the same example.
f(x) = x for 0<=x<=Pi/2
Pi-x for Pi/2<=x<=Pi

In[86]:=

  a0=(1/Pi) (Integrate[x,{x,0,Pi/2}]+
  Integrate[Pi-x,{x,Pi/2,Pi}])

Out[86]=

  Pi
  --
  4

In[87]:=

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

Out[87]=

      -2            -2             -2
  {0, --, 0, 0, 0, ----, 0, 0, 0, -----}
      Pi           9 Pi           25 Pi

Can you see the pattern?

Can you see the pattern? ...

Let's calculate some partial sums. Be patient.

In[88]:=

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

Let's see how we did.

In[89]:=

  Clear[sn1,sn3,sn5,sn10]

In[90]:=

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

In[91]:=

  sn3=Plot[a0+Sn[[3]],{x,0,Pi},DisplayFunction->Identity];
  Show[fgraph,sn3,PlotLabel->
  FontForm["a0+a1cos[x]+a2cos[2x]+a3cos[3x]",{"Helvetica-Bold",12}]];

In[92]:=

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

In[93]:=

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

You may have noticed that the sine series seemed to get to the answer quicker. You can see because so many of the ak terms were 0 so they did not contribute to the series. In general we must have the answer to the following question: How do I know whether to use the cosine series or the sine series?

You want your periodic extension to be smooth (no sharp turns or points). The smoother the extension, the faster the series will converge.

Recall that a sharp turn or point on the graph means that the derivative does not exist there!

In this example, using the odd periodic extension did not produce a sharp turn at x=0, the even periodic extension did.

Up to Half-Period Fourier Series