Solution (source code)

= Solution

For $L=1$, the <even function> $h(x)=x^2$ has $b_n=0$, because $x^2\sin(n\pi x)$ is an <odd function>. Its constant coefficient is $a_0=\int_{-1}^1x^2dx=2/3$. The remaining <Fourier coefficients> are
$$
a_n=2\int_0^1x^2\cos(n\pi x)\,dx.
$$
Two applications of <integration by parts> give the <antiderivative>, with $k=n\pi$,
$$
\frac{x^2\sin(kx)}k+\frac{2x\cos(kx)}{k^2}-\frac{2\sin(kx)}{k^3}.
$$
Its endpoint difference is $2(-1)^n/(n\pi)^2$, so $a_n=4(-1)^n/(n^2\pi^2)$. Therefore
$$
\boxed{x^2=\frac13+\frac4{\pi^2}\sum_{n=1}^{\infty}\frac{(-1)^n}{n^2}\cos(n\pi x),\qquad-1\leq x\leq1.}
$$
The periodic extension is continuous and piecewise smooth, so <pointwise convergence of a piecewise smooth Fourier series> gives equality, including at the endpoints.