<s>[INST] Series $\sum_{n=1}^{\infty}\frac{\cos(nx)}{n^2}$ Is it true that for $x\in[0,2\pi]$ we have
$$\sum_{n=1}^{\infty}\frac{\cos(nx)}{n^2}=\frac{x^2}{4}-\frac{\pi x}{2}+\frac{\pi^2}{6}$$
How can I prove it?
For other intervals what is the value of above series if is convergent?
 [/INST] Here there is a way using Fourier series. Consider the orthonormal basis of $L^{2}([0,2\pi])$, given by the functions
$$ e_{n}(x) = \frac{1}{\sqrt{2\pi}} e^{-i n x}, \quad n \in \mathbb{Z}. $$
Since for $x \in [0,2\pi]$ the indicator function $\mathbf{1}_{[0,x]}$ is in $L^{2}([0,2\pi])$, it can be expressed in its development in the basis $(e_{n})_{n}$. If we denote $(f,g)$ the dot-product of two functions $f,g$ in $L^{2}([0,2\pi])$, that is $$(f,g) = \int_{[0,2\pi]}f(x)\overline{g(x)}dx,$$ then we have
$$ x = (\mathbf{1}_{[0,x]} , \mathbf{1}_{[0,x]} ) = \sum_{n \in \mathbb{Z}} ( \mathbf{1}_{[0,x]} , e_{n} ) ( e_{n} , \mathbf{1}_{[0,x]}) =  \sum_{n \in \mathbb{Z}} |( \mathbf{1}_{[0,x]} , e_{n} )|^{2}. $$
The rest is just computing integrals and separating absolutely convergence series. We have
$$(\mathbf{1}_{[0,x]} , e_{n} ) = \frac{1}{\sqrt{2\pi}}\int_{0}^{x}e^{iny}dy =  \begin{cases}  \frac{e^{inx} - 1}{\sqrt{2\pi} ni}  & n \neq 0, \\
\frac{x}{\sqrt{2\pi}} & n = 0.
\end{cases} $$
Hence,
$$  x = \frac{x^{2}}{2\pi} + \frac{1}{2\pi}\sum_{\substack{n \in \mathbb{Z} \\ n \neq 0}} \frac{2-2\cos(nx)}{n^2}.  $$
Using symetric arguments ($ \frac{2-2\cos(nx)}{n^2} = \frac{2-2\cos(-nx)}{(-n)^2}$), we obtain
$$ x = \frac{x^{2}}{2\pi} + \frac{2}{\pi}\sum_{n=1}^{\infty} \frac{1}{n^{2}} - \frac{2}{\pi}\sum_{n=1}^{\infty}\frac{\cos(nx)}{n^{2}} = \frac{x^{2}}{2\pi} + \frac{\pi}{3} - \frac{2}{\pi}\sum_{n=1}^{\infty}\frac{\cos(nx)}{n^{2}}, $$
from where we finally obtain
$$ \sum_{n=1}^{\infty}\frac{\cos(nx)}{n^{2}} = \frac{x^{2}}{4} - \frac{\pi x}{2} + \frac{\pi^{2}}{6}. $$
Outside the interval, just use the periodicity of $\cos$.
</s>