Sum $\sum_{n = 1}^{\infty}\left[\frac1n\sin nx + \frac{1}{n^2}\cos nx\right]$ I want to find the following sum by using the complex methods for series ($z = \cos nx + i \sin nx$).
$$
\sum_{n = 1}^{\infty}\left[\frac1n\sin nx + \frac{1}{n^2}\cos nx\right]
$$
Here is my attempt:
$$
S_N =  \sum_{n = 1}^{N}\frac1n\sin nx + \sum_{n = 1}^{N}\frac{1}{n^2}\cos nx
$$
I'm done with the first sum:
$$
 \sum_{n = 1}^{N}\frac1n\sin nx  = \Im  \sum_{n = 1}^{N}\frac{z^n}{n} \Rightarrow \lim_{N \to \infty} \sum_{n = 1}^{N}\frac1n\sin nx = -\Im \ln(1 - z)
$$
But I'm stuck with the second one:
$$
\sum_{n = 1}^{N}\frac{1}{n^2}\cos nx = \Re \sum_{n = 1}^{N}\frac{z^n}{n^2}
$$
 A: Note that we have 
$$\int_0^x \sin(nt)\,dt=\frac{1-\cos(nx)}{n}$$
Therefore we can write for $x\in [0,2\pi]$
$$\begin{align}
\sum_{n=1}^\infty \frac{\cos(nx)}{n^2}&=\frac{\pi^2}{6}-\sum_{n=1}^\infty \frac1n \int_{0}^x \sin(nt)\,dt\\\\
&=\frac{\pi^2}{6}-\int_0^x \sum_{n=1}^\infty \frac{\sin(nt)}{n}\,dt\\\\
&=\frac{\pi^2}{6}+\int_0^x \text{Im}\left(\log(1-e^{ix})\right)\,dt\\\\
&=\frac{\pi^2}6-\int_0^x \arctan(\cot(t/2))\,dt \\\\
&=\frac{\pi^2}{6}-\int_0^x \left(\frac{\pi}{2}-\frac t2\right)\,dt\\\\
&=\frac{\pi^2}{6}-\frac\pi 2 x +\frac{x^2}{4}
\end{align}$$
A: Continue with 
\begin{align}
 \sum_{n = 1}^{\infty}\frac{\sin nx }n
= -\Im \ln(1 - z)
= \frac i2 [\ln( 1-z) -\ln (1-\bar z)]
=\frac i2\ln(-z)= \frac{\pi-x}2
\end{align}
and use the result to evaluate
$$
\sum_{n = 1}^{\infty}\frac{1- \cos nx }{n^2}=
\sum_{n = 1}^{\infty}\int_0^x \frac{\sin nt  }{n}dt
= \int_0^x \frac{\pi-t}{2}dt= \frac{\pi}2x-\frac14x^2
$$
Thus
\begin{align}
\sum_{n = 1}^{\infty}\left(\frac1n\sin nx + \frac{1}{n^2}\cos nx\right)
&= \frac{\pi-x}2 - \frac{\pi}2x+\frac14x^2
 + \sum_{n = 1}^{\infty}\frac{1}{n^2} \\
&=\frac{x^2}4 - \frac{(\pi+1)x-\pi}2 +\frac{\pi^2}6
\end{align}
A: $\newcommand{\bbx}[1]{\,\bbox[15px,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}$
$\ds{\bbox[15px,#ffd]{\sum_{n = 1}^{\infty}
\bracks{{\sin\pars{nx} \over n} + {\cos\pars{nx} \over n^{2}}}}:\
{\large ?}}$

\begin{align}
\sum_{n = 1}^{\infty}{\sin\pars{nx} \over n} & =
\Im\sum_{n = 1}^{\infty}{\pars{\expo{\ic x}}^{n} \over n} =
-\,\Im\ln\pars{1 - \expo{\ic x}}
\\[5mm] & =
-\,\Im\ln\pars{1 - \cos\pars{x} - \ic\sin\pars{x}}
\\[5mm] & =
-\arctan\pars{-\sin\pars{x} \over 1 - \cos\pars{x}} =
\arctan\pars{2\sin\pars{x/2}\cos\pars{x/2} \over 2\sin^{2}\pars{x/2}}
\\[5mm] & =
\arctan\pars{\cot\pars{x \over 2}} =
\arctan\pars{\tan\pars{{\pi \over 2} - {x \over 2}}} =
\bbx{{\pi \over 2} - {x \over 2}}\label{1}\tag{1}
\end{align}

\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\operatorname{Li}_{2}\pars{\exp\pars{2\pi\ic\,{x \over 2\pi}}}
\end{align}
where $\ds{\operatorname{Li}_{s}}$ is a
Polylogarithm
With the Jonqui$\grave{\mrm{e}}$re Inversion Formula
\begin{align}
\sum_{n = 1}^{\infty}{\cos\pars{nx} \over n^{2}} & =
-\,{1 \over 2}\,{\pars{2\pi\ic}^{2} \over 2!}
\operatorname{B}_{2}\pars{x \over 2\pi}
\end{align}
where $\ds{\operatorname{B}_{s}}$ is a
Bernoulli Polynomial. In particular,
$\ds{\operatorname{B}_{2}\pars{x} = x^{2} - x + 1/6}$.
Then,
\begin{align}
\sum_{n = 1}^{\infty}{\cos\pars{nx} \over n^{2}} & =
\pi^{2}
\bracks{\pars{x \over 2\pi}^{2} - {x \over 2\pi} + {1 \over 6}} =
\bbx{{1 \over 4}\,x^{2} - {\pi \over 2}\,x + {\pi^{2} \over 6}}
\label{2}\tag{2} 
\end{align}

Finally, with (\ref{1}) and (\ref{2}):
$$
\sum_{n = 1}^{\infty}
\bracks{{\sin\pars{nx} \over n} + {\cos\pars{nx} \over n^{2}}} =
\bbox[15px,#ffd,border:1px solid navy]{{1 \over 4}\,x^{2} - {1 + \pi \over 2}\,x + {\pi \over 2} +
{\pi^{2} \over 6}}
$$

