Limit of a sum using complex analysis. I'm trying to find the limit of this sum: $$S_n =\frac{1}{n}\left(\frac{1}{2}+\sum_{k=1}^{n}\cos(kx)\right)$$
I tried to find a formula for the inner sum first and I ended up getting zero as an answer.
The sum is supposed to converge to $\cot(x\over 2)$ and that appears in my last expression but it goes to zero.
Here is what I got with a rather long and clumsy reasoning:
$$S_n = \frac{1}{2n}\left(\cot\left(\frac{x}{2}\right)\sin(nx)+\cos(nx)\right)$$
Thanks in advance.

Just write $\cos (kx)$ as the real part of $e^{ikx}$.
