<s>[INST] 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}
$$
 [/INST] 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}
</s>