f(x)=x
In[39]:=
Clear[part1,part2,part3,part4]
part1=Plot[x+2Pi,{x,-3Pi,-Pi},DisplayFunction->Identity];
part2=Plot[x,{x,-Pi,Pi},DisplayFunction->Identity];
part3=Plot[x-2Pi,{x,Pi,3Pi},DisplayFunction->Identity];
part4=ListPlot[{{-3Pi,0},{-Pi,0},{Pi,0},{3Pi,0}}
,PlotStyle->{RGBColor[1,0,0],PointSize[.02]},DisplayFunction->Identity];
graphoff=Show[part1,part2,part3,part4,
DisplayFunction->$DisplayFunction,
AspectRatio->Automatic,Ticks->{{-3Pi,-Pi,Pi,3Pi},Automatic}];

Let's find the Fourier coefficients.
In[40]:=
Clear[a0,a,b,Sn]
a0=1/(2 Pi)Integrate[x,{x,-Pi,Pi}]
a[n_]:=1/Pi Integrate[x u[x,Pi,n],{x,-Pi,Pi}]
Table[a[k],{k,1,10}]
b[n_]:=1/Pi Integrate[x v[x,Pi,n],{x,-Pi,Pi}]
Table[b[k],{k,1,10}]
Out[40]=
0
Out[41]=
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
Out[42]=
2 1 2 1 2 1 2 1
{2, -1, -, -(-), -, -(-), -, -(-), -, -(-)}
3 2 5 3 7 4 9 5
Do the values of the coefficients surprise you?
Do the values of the coefficients surprise you? ...
Can you see the pattern in the bn values?
Can you see the pattern in the bn ...
Let's calculate a few partial sums.
In[43]:=
Sn=Table[Sum[b[k]v[x,Pi,k],{k,1,n}],{n,1,10}];
Let's see how we did.
In[44]:=
sn1=Plot[Sn[[1]],{x,-2 Pi,2 Pi},DisplayFunction->Identity];
Show[graphoff,sn1,DisplayFunction->$DisplayFunction,
PlotLabel->FontForm["b1Sin[x]",{"Helvetica-Bold",12}]];

In[45]:=
sn3=Plot[Sn[[3]],{x,-2 Pi,2 Pi},DisplayFunction->Identity];
Show[graphoff,sn3,PlotLabel->
FontForm["b1Sin[x]+b2Sin[2x]+b3Sin[3x]",{"Helvetica-Bold",12}]];

In[46]:=
sn5=Plot[Sn[[5]],{x,-2 Pi,2 Pi},DisplayFunction->Identity];
Show[graphoff,sn5, PlotLabel->
FontForm["Sum(k=1 to 5) bkSin[kx]",{"Helvetica-Bold",12}]];

In[47]:=
sn10=Plot[Sn[[10]],{x,-2 Pi,2 Pi},DisplayFunction->Identity];
Show[graphoff,sn10, PlotLabel->
FontForm["Sum(k=1 to 10) bkSin[kx]",{"Helvetica-Bold",12}]];

Notice the Gibbs Phenomenon , as described in many texts.
Let's also investigate what happens at the points of discontinuity. For this function they are x= . . . -3Pi, -Pi, Pi, 3Pi, . . .
In[48]:=
Sn/.x->Pi
Sn/.x->-Pi
Sn/.x->3 Pi
Out[48]=
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
Out[49]=
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
Out[50]=
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
The Fourier series is picking up the points from the periodic extension! Indeed it is converging to the midpoint of the jumps.
Remember, what is happening here is an illustration of one of our Sturm-Liouville theorems.
A Convergence Theorem:
If f is defined and is piecewise continuous on [-T, T], (that is, discontinuous
at only finitely many points) then the orthogonal series of f converges to the
mean value
1/2 [f(x0+) + f(x0-)] at each point at which left and right hand derivatives of
f both exist.
Let's recall note of a few things.
A. If f is continous at x0, the mean value of the left and right hand limits is
just f(x0), since f(x0-)=f(x0+)=f(x0). So,
Under the stated hypotheses, the Fourier series of f(x) converges to f(x)
everywhere that f(x) is continuous.
If f(x) has a jump discontinuity, then
Under the stated hypotheses, the Fourier series of f(x) converges to the
average value at the jump everywhere f(x) has a jump discontinuity.
In terms of some of our new terminology, this theorem really says that
the Fourier series of f(x) converges to the periodic extension of f(x).
Just for completeness, this theorem is only a sufficient condition for the stated convergence; that is, you may have the stated convergence even if f does not meet the hypotheses.
In[51]:=
Up to Fourier Series Examples