CONVERGENCE OF FOURIER SERIES USING MATHEMATICA

Consider the simple function:

f(x) = ({{{, ({{1,, 0<x<π}, {0,, -π<x<0}})}})

Clear[f]
f[x_]:=Which[-π<x<0,0,0<x<π,1]
Plot[f[x],{x,-π,π}]

You should be able to compute the Fourier series to be:

f(x) = (1/2)+(2/π)(Underoverscript[Σ, (n=1, 3, 5), ∞])((sin(n x) )/n)                      (where the sum is over the odd integers)

1)  Write the Mathematica code that will compute the series out to the n=7 term (the first three sin terms), and plot the series between -π and π.

Plot[1/2+(2/π)Sum[Sin[n x]/n,{n,1,7,2}],{x,-π,π}]

Your result should resemble the graph of the original function.  Now, plot the series out to n=13 (the next three terms):

Plot[1/2+(2/π)Sum[Sin[n x]/n,{n,1,13,2}],{x,-π,π}]

What differences do you observe between the two plots?  Does it seem that the series is converging to the function?  Now, try plotting out to n=31:

Plot[1/2+(2/π)Sum[Sin[n x]/n,{n,1,31,2}],{x,-π,π}]

And we can have confidence that a series of sine waves can be summed to converge to a square wave.

2)  Now, make use of the Manipulate command, and allow the upper limit of the summation to be a variable which we can call nterms.  Use the Manipulate command to see how the series approaches convergence as nterms increases :

Manipulate[Plot[1/2+(2/π)Sum[Sin[n x]/n,{n,1,nterms,2}],{x,-π,π}],{nterms,1,101}]

Use the slider to see how the series converges to the square wave as you add more and more terms of the form sin(n x)/n.  Note that “spikes” appear at the discontinuities (x = -π, x=0, x = π) even when the upper limit of the sum is n = 101.  These spikes are the Gibbs phenomenon and are the result of trying to fit a discontinuous function with a finite set of sine/cosine curves.  The amount of overshoot will be approximately 9 % of the height of the discontinuity.

3)  Consider the function :

f(x) = ({{{, ({{-x,, -π<x<0}, {x,, 0<x<π}})}})

a) Find the Fourier coefficients for this function and then write the series in closed summation format.

ANS: f(x) = (π/2)-(4/π)(Underoverscript[Σ, odd, ∞])((Cos[n x])/(n^2))    (where the sum is over the odd integers)

b)  Plot the Fourier series out to the n = 7 term.

Plot[π/2-(4/π)Sum[Cos[n x]/n^2,{n,1,7,2}],{x,-π,π}]

How rapidly is this series converging to the function?  Do you think this series is converging more or less rapidly to the function than the series in problem 1)?  What property of this series explains your answer?