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.

You have, for all $x \neq 2k\pi$, 
$$\sum_{k=1}^n \cos(kx) = \mathrm{Re}\left( \sum_{k=1}^n e^{ikx}\right) = \mathrm{Re}\left( e^{ix} \frac{1-e^{inx}}{1-e^{ix}} \right)$$
Moreover you have
$$\left|e^{ix} \frac{1-e^{inx}}{1-e^{ix}}\right| \leq \frac{2}{|1-e^{ix}|}$$
So $$\left| \sum_{k=1}^n \cos(kx) \right| \leq \frac{2}{|1-e^{ix}|}$$
And therefore you get $S_n \rightarrow 0$.
If $x = 2k\pi$ for $k \in \mathbb{Z}$, you easily have $S_n \rightarrow 1$.
