TITLE: Sum of $\cos(k x)$
QUESTION [10 upvotes]: I'm trying to calculate the trigonometric sum : $$\sum\limits_{k=1}^{n}\cos(k x)$$
This is what I've tried so far : $$\renewcommand\Re{\operatorname{Re}}
\begin{align*}
\sum\limits_{k=1}^{n}\cos(k x) &= \Re\left(\sum\limits_{k=1}^{n}e^{i k x}\right)\\
&= \Re\left(e^{i x}\frac{1 - e^{inx}}{1 - e^{ix}}\right)
\end{align*}$$
How can I go on ?

REPLY [17 votes]: Here's a slightly different approach than André's one, you may find it easier and less error prone (it doesn't involve common denominators or long expansions). There's also a useful trick in it, so it's not completely uninteresting.
$$\begin{align}
\sum_{k=1}^n \cos(kx) & =  \Re\left(\sum_{k=1}^n e^{ikx}\right)\\
& = \Re\left(e^{ix} {e^{inx}-1 \over e^{ix}-1}\right) \\
& = \Re\left({e^{ix} e^{inx \over 2} \over e^{ix \over 2}} {e^{inx \over 2} - e^{-inx \over 2} \over e^{ix \over 2} - e^{-ix\over2}}\right)\\
& = \Re\left( e^{i(n+1)x \over 2} {\sin{nx\over2} \over \sin{x \over 2}}\right)\\
& = {\sin{nx\over2} \over \sin{x \over 2}} \cos\left({(n+1)x\over2}\right)
\end{align}$$
The trick is between lines 2 and 3, where you factor by the "half-angle" exponential to make a sine appear. As in André's proof you need to distinguish the case $e^{ix} = 1$.