> # FOURIER SINE SERIES OF A SQUARE WAVE

>

> # f(x) = 1 on (0,Pi); f(x) = -1 on (-Pi,0); f has period 2*Pi.

>

> # First we need to calculate the Fourier coefficients.

> bn := (2/Pi)*Int(sin(n*x), x=0..Pi);

bn := 2*Int(sin(n*x),x = 0 .. Pi)/Pi

> value(%);

-2*(cos(Pi*n)-1)/(Pi*n)

> # This is 0 unless n is odd.

>

> # Note that, unlike the coefficients of the triangle wave, these decrease like 1/n, not 1/n^2.

>

> bodd := k -> (4/Pi)*(1/(2*k+1));

bodd := proc (k) options operator, arrow; 4*1/(Pi*(...

> partialsum := K -> sum(bodd(k)*sin((2*k+1)*x), k=0..K);

partialsum := proc (K) options operator, arrow; sum...

> plot(partialsum(0), x=-8..8);

[Maple Plot]

> plot(partialsum(1), x=-8..8);

[Maple Plot]

> plot(partialsum(2), x=-8..8);

[Maple Plot]

> plot(partialsum(4), x=-8..8);

[Maple Plot]

> plot(partialsum(8), x=-8..8);

[Maple Plot]

> plot(partialsum(16), x=-8..8);

[Maple Plot]

> # Let's look up close.

> plot(partialsum(16), x=-1..4);

[Maple Plot]

> plot(partialsum(32), x=-1..4);

[Maple Plot]

> plot(partialsum(64), x=-1..4);

[Maple Plot]

>