Sum to n terms the series $\cos \theta+ 2\cos 2\theta+ \cdots + n\cos n\theta$ Sum to $n$ terms and also to infinity of the following series:$$\cos \theta+ 2\cos 2\theta+ \cdots + n\cos n\theta$$the solution provided by the book is $$S_n=\frac{(n+1)\cos n\theta-n\cos(n+1)\theta-1}{2(1-\cos\theta)}$$Can anyone help me to explain how to get $S_n$.
Thanks in advance.
 A: Hint: Take integral you get:
$$
(\sin x+\sin 2x+\sin 3x+\dots+\sin nx)=\frac{\cos x/2 - \cos (n+ 1/2)x}{2 \sin x/2}
$$
Now take the derivative.
A: To find closed form for series of $\cos$ and $\sin$ functions, approach using complex numbers helps very much. Consider, $z=e^{i\theta}$, where, $i=\sqrt{-1}$. We need to construct a function whose real part or imaginary part(otherwise we will have $i$ in the sum, which we don't have in the sum we are interested to find out) will give the required sum. Now, if we take $f(z)=1+z+z^2+z^3+\cdots +z^n$, 
$$z\cdot f'(z)=z+2z^2+3z^3+\cdots+nz^{n}\\=\cos{\theta}+2\cos{2\theta}+\cdots+\cos{n\theta}+i\sum_{k=1}^{n}k\cdot\sin{(k\theta)} $$
So, notice that $\Re{\{z\cdot f'(z)\}}$ is the required sum. On the other hand, $f(z)=\frac{z^{n+1}-1}{z-1} $ gives, $$\require{cancel}z\cdot f'(z)=z\cdot \frac{(z-1)\cdot (n+1)z^n-z^{n+1}+1}{(z-1)^2}=z\cdot \frac{(n+\cancel{1})z^{n+1}-(n+1)z^n-\cancel{z^{n+1}}+1}{(z-1)^2}\\= z^{n+1}\cdot \frac{n(z-1)-1}{(z-1)^2} $$
Now, $\sum_{k=1}^{n}k\cdot \cos{(k\theta)}=\Re{\{z\cdot f'(z)\}}=\Re{\{z^{n+1}\cdot \frac{n(z-1)-1}{(z-1)^2}\}}$. After some calculation you will get the result.
