Sum of $\cos(k x)$ [duplicate]

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$.


Expressing in terms of complex exponentials is a good start. You used $$\cos(kx)=\frac{e^{ikx}+e^{-ikx}}{2}.$$ Now $\sum_{k=1}^n e^{ikx}$ is the sum of a finite geometric series, as is the sum of the other terms. So our sum is equal to $$\frac{1}{2}\left(\frac{e^{ix}(1-e^{inx})}{1-e^{ix}}+\frac{e^{-ix}(1-e^{-inx})}{1-e^{-ix}}\right).$$ You are probably expected to express things in terms of real functions. So bring to a common denominator. At the bottom we get $(1-e^{ix})(1-e^{-ix})$. If you multiply this out and recognize that $e^{ix}+e^{-ix}=2\cos x$, you end up with $2-2\cos x$. If you feel like it, this can be in a sense simplified by using the identity $\cos 2\theta=2\cos^2\theta-1$.

After you bring things to a common denominator, expand the messy top that you get. It is easy, but with ample opportunities for error. The terms you get combine nicely in pairs into (twice) cosines, apart from a couple of terms that are each simply $-1$.

The above calculation works when $1-e^{ix}\ne 0$ ($\cos x\ne 1$). For completeness, we need to deal with the case $\cos x=1$. In that case the sum is $n$.