Let $S=S_1+S_2i$ $; S_1=\cos x+ \cos 2x + ...+ \cos nx $ $;S_2 \sin x + \sin 2x+...+ \sin nx $ and $z=\cos x + i\sin x$, then:
$$S=S_1+S_2i=z+z^2+...+z^n=z \frac{z^n-1}{z-1}=\frac{(\cos(n+1)x+\cos x)+i(\sin(n+1)x- \sin x)}{\cos x-1 + i\sin x -1}$$ Well, what I don't understand is this last line because I got something different: The only difference being that in the denominator being $\cos x+ i \sin x -1$ because $z-1?$ Then it goes on to say: $S_1= ReS$ and $S_2=Im S$ then (this I don't know how it is derived): $$S_1=\frac{\sin\frac{(n+1)x}{2}}{\sin \frac{x}{2}}\cos {(x+ \frac{nx}{2})} $$ $$S_2= \frac{\sin\frac{(n+1)x}{2} }{\sin \frac{x}{2}}\sin(x+\frac{nx}{2}) $$