How to find $\sum_{r=1}^{n} r^2\cos {(r\theta)}$ How do you find the sum $$S(\theta)=\displaystyle\sum_{r=1}^{n} r^2\cos {(r\theta)}$$?
I observed that if $f(\theta)$ is $\sum\cos {(r\theta)}$, then $S(\theta)=-f''(\theta)$.
Help will be appreciated.
 A: $\cos x$ is the real part of $e^{ix}$. So $\sum_{k=1}^n\cos(k\theta)$ is the real part of $\sum_{k=1}^n \left(e^{i\theta}\right)^k$. Letting $z=e^{i\theta}$, this is:
$$z\frac{z^n-1}{z-1} = \frac{z^{n+1}-z}{z-1}\frac{z^{-1} - 1}{z^{-1}-1} = \frac{z^{n}-1-z^{n+1}+z}{2-z-z^{-1}}$$
Now $z^{-1}=\cos\theta -i\sin\theta = \bar z$, and $2-z-z^{-1}=2-2\cos\theta$. So the real part is:
$$\frac{\cos n\theta  -\cos (n+1)\theta +\cos\theta-1 }{2-2\cos\theta}=-\frac12 +\frac{\cos n\theta-\cos(n+1)\theta}{2-2\cos\theta}$$
So that is the value of $\sum_{k=1}^n \cos k\theta$, and you'll have to take the double derivative to get $-\sum k^2\cos k\theta$. That's gonna be ugly.
A: Let us find $\displaystyle S=\sum_{r=1}^nr^2z^r$ where $z=e^{i\theta}$
We need to find the real part of $S$
$z\cdot S=n^2z^{n+1}+\sum_{r=2}^n(r-1)^2z^r$
$\displaystyle\implies(z-1)S=n^2z^{n+1}-\sum_{r=1}^n(2r-1)z^r$
Let $\displaystyle T=\sum_{r=1}^n(2r-1)z^r$
$\displaystyle\implies z\cdot T=\sum_{r=1}^n(2r-1)z^{r+1}=(2n+1)z^{n+1}+\sum_{r=2}^n(2r-3)z^r$
$\displaystyle\implies (z-1)T=(2n+1)z^{n+1}-2\sum_{r=2}^nz^r,$ the last part is clearly a finite Geometric Series
Can you take it home from here?
