fourier01.mw

Fourier Series Examples

Consider the function we discussed in class.  The period is

 > f := x -> piecewise(x<0, 0, 1);

 > plot(f(x), x=-Pi..Pi, y=-.5..1.5, color=black, axes=framed, discont=true);

 > with(plots):

Warning, the name changecoords has been redefined

 >

Here's the picture for 3 periods.

 > display([plot(f(x+2*Pi), x=-3*Pi..-Pi, discont=true), plot(f(x), x=-Pi..Pi, discont=true), plot(f(x-2*Pi), x=Pi..3*Pi, discont=true)], axes=framed, view=[-3*Pi..3*Pi, -.5..1.5]);

 >

Now let's compute the fourier coefficents

 > a[0] := (1/(2*Pi))*Int(f(x), x=-Pi..Pi);

 > a[0]:=value(a[0]);

 > n := 'n';

 > an:= (1/Pi)*Int(f(x)*cos(n*x), x=-Pi..Pi);

 > an:= value(an);

 >

But this is zero, since n is an integer.

 > bn:= (1/Pi)*Int(f(x)*sin(n*x), x=-Pi..Pi);

 > bn := value(bn);

 >

Since n is an integer, .  To get the computer to see this, we have to tell it that n is an integer

 > assume(n, posint);

 >

 > bn;

 >

This is 0 if n is even and if n is odd.   Hence the fourier seris is

 > 1/2 + Sum(2/((2*k+1)*Pi)*sin((2*k+1)*x), k=0..infinity);

 > partsum := m -> 1/2+add(2/((2*k+1)*Pi)*sin((2*k+1)*x), k=0..m);

 > partsum(5);

 >

Now, lets compare the partial sums of the Fourier series to the function on the interval .

 > plot({f(x), 1/2}, x=-Pi..Pi, y=-.5..1.5, axes=framed, discont=true, color=black);

 > plot({f(x), partsum(0)}, x=-Pi..Pi, y=-.5..1.5, axes=framed, discont=true, color=black);

 > plot({f(x), partsum(1)}, x=-Pi..Pi, y=-.5..1.5, axes=framed, discont=true, color=black);

 > plot({f(x), partsum(2)}, x=-Pi..Pi, y=-.5..1.5, axes=framed, discont=true, color=black);

 > plot({f(x), partsum(3)}, x=-Pi..Pi, y=-.5..1.5, axes=framed, discont=true, color=black);

 > plot({f(x), partsum(4)}, x=-Pi..Pi, y=-.5..1.5, axes=framed, discont=true, color=black);

 > plot({f(x), partsum(5)}, x=-Pi..Pi, y=-.5..1.5, axes=framed, discont=true, color=black);

 > plot({f(x), partsum(6)}, x=-Pi..Pi, y=-.5..1.5, axes=framed, discont=true, color=black);

 > plot({f(x), partsum(10)}, x=-Pi..Pi, y=-.5..1.5, axes=framed, discont=true, color=black);

 > plot({f(x), partsum(20)}, x=-Pi..Pi, y=-.5..1.5, axes=framed, discont=true, color=black, numpoints=300);

 > plot({f(x), partsum(50)}, x=-Pi..Pi, y=-.5..1.5, axes=framed, discont=true, color=black, numpoints=300);

 >

Let's do a few of these with a view of 3 periods.

 > display([plot(f(x+2*Pi), x=-3*Pi..-Pi, discont=true, color=black), plot(f(x), x=-Pi..Pi, discont=true, color=black), plot(f(x-2*Pi), x=Pi..3*Pi, discont=true, color=black), plot(1/2, x=-3*Pi..3*Pi, color=black)], axes=framed, view=[-3*Pi..3*Pi, -.5..1.5]);

 > display([plot(f(x+2*Pi), x=-3*Pi..-Pi, discont=true, color=black), plot(f(x), x=-Pi..Pi, discont=true, color=black), plot(f(x-2*Pi), x=Pi..3*Pi, discont=true, color=black), plot(partsum(0), x=-3*Pi..3*Pi, color=black)], axes=framed, view=[-3*Pi..3*Pi, -.5..1.5]);

 > display([plot(f(x+2*Pi), x=-3*Pi..-Pi, discont=true, color=black), plot(f(x), x=-Pi..Pi, discont=true, color=black), plot(f(x-2*Pi), x=Pi..3*Pi, discont=true, color=black), plot(partsum(1), x=-3*Pi..3*Pi, color=black)], axes=framed, view=[-3*Pi..3*Pi, -.5..1.5]);

 > display([plot(f(x+2*Pi), x=-3*Pi..-Pi, discont=true, color=black), plot(f(x), x=-Pi..Pi, discont=true, color=black), plot(f(x-2*Pi), x=Pi..3*Pi, discont=true, color=black), plot(partsum(2), x=-3*Pi..3*Pi, color=black)], axes=framed, view=[-3*Pi..3*Pi, -.5..1.5]);

 > display([plot(f(x+2*Pi), x=-3*Pi..-Pi, discont=true, color=black), plot(f(x), x=-Pi..Pi, discont=true, color=black), plot(f(x-2*Pi), x=Pi..3*Pi, discont=true, color=black), plot(partsum(3), x=-3*Pi..3*Pi, color=black)], axes=framed, view=[-3*Pi..3*Pi, -.5..1.5]);

 > display([plot(f(x+2*Pi), x=-3*Pi..-Pi, discont=true, color=black), plot(f(x), x=-Pi..Pi, discont=true, color=black), plot(f(x-2*Pi), x=Pi..3*Pi, discont=true, color=black), plot(partsum(10), x=-3*Pi..3*Pi, color=black)], axes=framed, view=[-3*Pi..3*Pi, -.5..1.5]);

 >