fourier01.mw

Fourier Series Examples

Consider the function we discussed in class.  The period is 2*Pi

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

f := proc (x) options operator, arrow; piecewise(x < 0, 0, 1) end proc

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

[Plot]

> 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]);

[Plot]

>

Now let's compute the fourier coefficents

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

a[0] := 1/2*Int(PIECEWISE([0, x < 0], [1, otherwise]), x = (-Pi .. Pi))/Pi

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

a[0] := 1/2

> n := 'n';

n := n

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

an := Int(PIECEWISE([0, x < 0], [1, otherwise])*cos(n*x), x = (-Pi .. Pi))/Pi

> an:= value(an);

an := sin(Pi*n)/(Pi*n)

>

But this is zero, since n is an integer.

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

bn := Int(PIECEWISE([0, x < 0], [1, otherwise])*sin(n*x), x = (-Pi .. Pi))/Pi

> bn := value(bn);

bn := -(cos(Pi*n)-1)/(Pi*n)

>

Since n is an integer, cos(n*Pi) = (-1)^n .  To get the computer to see this, we have to tell it that n is an integer

> assume(n, posint);

>

> bn;

-((-1)^n-1)/(Pi*n)

>

This is 0 if n is even and 2/n*Pi 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);

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

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

partsum := proc (m) options operator, arrow; 1/2+add(2*sin((2*k+1)*x)/((2*k+1)*Pi), k = (0 .. m)) end proc

> partsum(5);

1/2+2*sin(x)/Pi+2/3*sin(3*x)/Pi+2/5*sin(5*x)/Pi+2/7*sin(7*x)/Pi+2/9*sin(9*x)/Pi+2/11*sin(11*x)/Pi

>

Now, lets compare the partial sums of the Fourier series to the function on the interval [-Pi, Pi] .

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

[Plot]

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

[Plot]

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

[Plot]

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

[Plot]

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

[Plot]

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

[Plot]

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

[Plot]

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

[Plot]

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

[Plot]

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

[Plot]

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

[Plot]

>

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]);

[Plot]

> 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]);

[Plot]

> 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]);

[Plot]

> 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]);

[Plot]

> 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]);

[Plot]

> 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]);

[Plot]

>