Solution (source code)

= Solution

The periodically extended $x^2$ is <even>, so every sine coefficient is zero. With the convention $f=a_0/2+\sum_{n\geq1}(a_n\cos nx+b_n\sin nx)$, the <Fourier coefficients> are
$$
a_0=\frac2\pi\int_0^\pi x^2dx=\frac{2\pi^2}3,\qquad a_n=\frac2\pi\int_0^\pi x^2\cos nx\,dx=\frac{4(-1)^n}{n^2}.
$$
For the second integral, two applications of <integration by parts> give $\int_0^\pi x^2\cos nx\,dx=2\pi(-1)^n/n^2$. Consequently
$$
\boxed{x^2=\frac{\pi^2}3+4\sum_{n=1}^\infty\frac{(-1)^n\cos nx}{n^2},\qquad -\pi\leq x\leq\pi.}
$$
The periodic extension is continuous even at the joined endpoints, where both one-sided values equal $\pi^2$. The <pointwise convergence of a piecewise smooth Fourier series> therefore gives the displayed values throughout the interval; the coefficient bound also gives <uniform convergence> by the <Weierstrass M-test>. Setting $x=\pi$ and then $x=0$ yields
$$
\boxed{\sum_{n=1}^\infty\frac1{n^2}=\frac{\pi^2}6,\qquad \sum_{n=1}^\infty\frac{(-1)^{n+1}}{n^2}=\frac{\pi^2}{12}.}
$$