Solution (source code)

= Solution

The analogous <orthogonal projection> onto the cosine terms gives
$$
\boxed{a_n=\frac1L\int_{-L}^{L}f(x)\cos(n\pi x/L)\,dx,\qquad n\geq0}.
$$
For $n=0$, this means $a_0=L^{-1}\int_{-L}^{L}f(x)\,dx$; the actual constant in the <Fourier series> is $a_0/2$ because the constant function has squared <norm> $2L$.