Solution (source code)

= Solution

Use the period-two <Fourier series> convention
$$
f(x)\sim\frac{a_0}{2}+\sum_{n=1}^{\infty}\bigl[a_n\cos(n\pi x)+b_n\sin(n\pi x)\bigr].
$$
Away from its jumps this <square wave> is an <odd function>, so $a_0=a_n=0$. Its <Fourier sine coefficients> are
$$
b_n=\int_{-1}^1f(x)\sin(n\pi x)\,dx
=2\int_0^1\sin(n\pi x)\,dx
=\frac{2(1-(-1)^n)}{n\pi}.
$$
Only odd <Fourier harmonics> remain. Therefore
$$
\boxed{f(x)\sim\frac4\pi\sum_{j=0}^{\infty}\frac{\sin((2j+1)\pi x)}{2j+1}.}
$$
The <Fourier series> equals $f(x)$ away from the jumps; at a jump it gives the midpoint of the one-sided limits by <Dirichlet's theorem on Fourier series>. The printed definition leaves the values at the integers unspecified. Choosing finite values there consistent with period two changes neither the <Fourier coefficients> nor these limiting values.

\Image[/past-exam-of-the-year-1-of-the-computer-science-course-of-the-university-of-oxford/2015/discrete-resit-2015-square-wave.png]
{title=Odd Fourier harmonics approximate the period-two square wave and vanish at every jump}