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?
 A: The sum term  $$T(x) = \sum_{n\ge 1}\frac{\cos(nx)}{n^2}
= x^2 \sum_{n\ge 1}\frac{\cos(nx)}{(xn)^2}$$ is harmonic and may be evaluated by inverting it's Mellin transform.
Put $$S(x) = \sum_{n\ge 1}\frac{\cos(nx)}{(xn)^2}$$
and recall the harmonic sum identity
$$\mathfrak{M}\left(\sum_{k\ge 1} \lambda_k g(\mu_k x);s\right) =
\left(\sum_{k\ge 1} \frac{\lambda_k}{\mu_k^s} \right) g^*(s)$$
where $g^*(s)$ is the Mellin transform of $g(x).$
In the present case we have
$$\lambda_k = 1, \quad \mu_k = k \quad \text{and} \quad
g(x) = \frac{\cos x}{x^2}.$$
We need the Mellin transform $g^*(s)$ of $g(x)$ which is
$$\int_0^\infty \frac{\cos x}{x^2} x^{s-1} dx
= \int_0^\infty \cos x \times x^{(s-2)-1} dx.$$
Now the Mellin transform of $\cos(x)$ was computed at this MSE link and found to be 
$$\Gamma(s) \cos(\pi s/2)$$
and therefore
$$g^*(s) = \Gamma(s-2) \cos(\pi (s-2)/2)
= \Gamma(s-2) \cos(\pi s/2 - \pi) = -\Gamma(s-2) \cos(\pi s/2).$$
Therefore the Mellin transform $Q(s)$ of $S(x)$ is given by
$$ Q(s) = -\Gamma(s-2) \cos(\pi s/2) \zeta(s)
\quad\text{because}\quad
\sum_{k\ge 1} \frac{\lambda_k}{\mu_k^s} = \zeta(s).$$
Therefore the Mellin inversion integral for an expansion about zero is
$$\frac{1}{2\pi i} \int_{5/2-i\infty}^{5/2+i\infty} Q(s)/x^s ds$$
which we evaluate in the left half-plane $\Re(s)<5/2.$
The cosine term cancels the poles of the gamma function term at odd negative integers and the zeta function term the poles at even negative integers. We are left with just three poles.
$$\begin{align}
\mathrm{Res}(Q(s)/x^s; x=2) & = \frac{\pi^2}{6x^2} \\
\mathrm{Res}(Q(s)/x^s; x=1) & = -\frac{\pi}{2x} \quad\text{and}\\
\mathrm{Res}(Q(s)/x^s; x=0) & = \frac{1}{4}.
\end{align}$$
Hence in a neighborhood of zero,
$$S(x) =  \frac{\pi^2}{6x^2} -\frac{\pi}{2x} +\frac{1}{4}.$$
Using $T(x) = x^2 S(x)$ this finally yields in a neigborhood of zero that
$$T(x) =  \frac{\pi^2}{6} -x\frac{\pi}{2} +x^2\frac{1}{4}.$$
Since $T(x)$ is periodic with period $2\pi$ the interval this approximation is good in $(0,2\pi).$
There is a theorem hiding here, namely that certain Fourier series can be evaluated by inverting their Mellin transforms which is not terribly surprising and which the reader is invited to state and prove.
A: From here we have 
$$\sum_{n=1}^{\infty}\frac{\sin nx}{n}=\frac{\pi-x}{2}\quad (0<x<2\pi)$$
Integrate both sides with respect to $x$
$$-\sum_{n=1}^{\infty}\frac{\cos nx}{n^2}=\frac{\pi x}{2}-\frac{x^2}{4}+C$$
Set $x=0\Longrightarrow C=-\zeta(2)=-\frac{\large \pi^2}{6}$ 
Giving us 
$$\sum_{n=1}^{\infty}\frac{\cos(nx)}{n^2}=\frac{x^2}{4}-\frac{\pi x}{2}+\frac{\pi^2}{6}$$
A: $\newcommand{\bbx}[1]{\,\bbox[8px,border:1px groove navy]{\displaystyle{#1}}\,}
 \newcommand{\braces}[1]{\left\lbrace\,{#1}\,\right\rbrace}
 \newcommand{\bracks}[1]{\left\lbrack\,{#1}\,\right\rbrack}
 \newcommand{\dd}{\mathrm{d}}
 \newcommand{\ds}[1]{\displaystyle{#1}}
 \newcommand{\expo}[1]{\,\mathrm{e}^{#1}\,}
 \newcommand{\ic}{\mathrm{i}}
 \newcommand{\mc}[1]{\mathcal{#1}}
 \newcommand{\mrm}[1]{\mathrm{#1}}
 \newcommand{\pars}[1]{\left(\,{#1}\,\right)}
 \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}}
 \newcommand{\root}[2][]{\,\sqrt[#1]{\,{#2}\,}\,}
 \newcommand{\totald}[3][]{\frac{\mathrm{d}^{#1} #2}{\mathrm{d} #3^{#1}}}
 \newcommand{\verts}[1]{\left\vert\,{#1}\,\right\vert}$
\begin{align}
\sum_{n = 1}^{\infty}{\cos\pars{nx} \over n^{2}} & =
\Re\sum_{n = 1}^{\infty}{\pars{\expo{\ic x}}^{n} \over n^{2}} =
\Re\,\mrm{Li}_{2}\pars{\exp\pars{2\pi\ic\,{x \over 2\pi}}}
\\[5mm] & = 
-\,{1 \over 2}\,{\pars{2\pi\ic}^{2} \over 2!}\,\mrm{B}_{2}\pars{x \over 2\pi}
\label{1}\tag{1}
\end{align}
where we used Jonquiere Inversion Formula. $\ds{\,\mrm{B}_{n}\pars{x}}$ is a Bernoulli Polynomial. $\ds{\,\mrm{B}_{2}\pars{x} = x^{2} - x + {1 \over 6}}$

\eqref{1} becomes:
$$
\bbx{\ds{%
\sum_{n = 1}^{\infty}{\cos\pars{nx} \over n^{2}} =
{x^{2} \over 4} - {\pi x \over 2} + {\pi^{2} \over 6}}}\,,\quad
\left\{\begin{array}{rcl}
\ds{x \in \left[0,2\pi\right)} & \mbox{if} & \ds{\Im\pars{x} \geq 0}
\\[2mm] 
\ds{x \in \left(0,2\pi\right]} & \mbox{if} & \ds{\Im\pars{x} < 0}\\ &
\end{array}\right.
$$
A: See the results posted here, where I show that
$$\sum_{n=-\infty}^{\infty} \frac{\sin^2{a n}}{n^2} = \pi a$$
when $a \in (0,\pi)$.  Now, use the fact that 
$$\sum_{n=1}^{\infty} \frac{1}{n^2} = \frac{\pi^2}{6}$$
and let $S$ be the sum in question.  Then
$$\frac{\pi^2}{6} - S = \sum_{n=1}^{\infty} \frac{1-\cos{n x}}{n^2} = 2 \sum_{n=1}^{\infty} \frac{\sin^2{n x/2}}{n^2}$$
Rewrite the last sum as
$$2 \sum_{n=1}^{\infty} \frac{\sin^2{n x/2}}{n^2} = \sum_{n=-\infty}^{\infty} \frac{\sin^2{n x/2}}{n^2} - \left ( \frac{x}{2} \right )^2 = \pi \frac{x}{2} - \frac{x^2}{4}$$
Then
$$\frac{\pi^2}{6} - S =  \pi \frac{x}{2} - \frac{x^2}{4} \implies S = \frac{x^2}{4} - \pi \frac{x}{2} + \frac{\pi^2}{6}$$
as was to be shown.
A: 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$.
A: Another way to solve this is by finding the fourier series of x^2, then solving for (x+pi)^2 with the cosine addition formula.
