# What is $\cos x-\cos2x+\cos3x-\cos4x...\pm\cos(Nx)$?

I want to arrive at a closed expression for $$f_N(x)=\frac{2}{π}(\cos x-\cos2x+\cos3x-\cos4x...\pm \cos Nx)$$ ($$+\cos(Nx)$$ if $$N$$ is odd, $$-\cos(Nx)$$ if $$N$$ is even)

Using the fact that $$\cos(x)=\frac{e^{ix}+e^{-ix}}{2}$$ and $$\sin(x)=\frac{e^{ix}-e^{-ix}}{2i}$$, and by expressing our function as a G.P. with common ratio $$-e^{-ix}$$, I was able to express $$f_N(x)$$ (when $$N$$ is odd) as:

$$(\frac{1}{π}•\frac{e^{Nix}-e^{-Nix}}{1+e^{-ix}})+\frac{1}{π}$$

However I got stuck when I tried to simplify the above equation in terms of trigonometric terms. I was only able to simplify upto:

$$\frac{-1}{π}•\frac{\sin(Nx)•2i}{1+e^{-ix}}+\frac{1}{π}$$

I was a bit worried I had done something wrong while expressing the function as a G.P. but I checked my work and it seems fine.

I guess that the answer lies in some simple manipulation of terms but unfortunately, I was not able to find the solution to this problem.

Appreciate any help :)

• what kind of simplification you want ? Jun 20 '20 at 9:23
• A simplification in terms of sines and cosines, if possible Jun 20 '20 at 9:26

Expanding on @Bernard's answer, for even $$N$$ the sum is\begin{align}\Re\left[e^{ix}\frac{1-e^{iNx}}{1+e^{ix}}\right]&=\Re\left[e^{ix}\frac{-2ie^{iNx/2}\sin\frac{Nx}{2}}{2\cos\frac{x}{2}e^{ix/2}}\right]\\&=\Im\left[e^{i(N+1)x/2}\frac{\sin\frac{Nx}{2}}{\cos\frac{x}{2}}\right]\\&=\frac{\sin\frac{Nx}{2}\cos\frac{(N+1)x}{2}}{\cos\frac{x}{2}},\end{align}while for odd $$N$$ it's$$\Re\left[e^{ix}\frac{1+e^{iNx}}{1+e^{ix}}\right]=\Re\left[e^{i(N+1)x/2}\frac{\cos\frac{Nx}{2}}{\cos\frac{x}{2}}\right]=\frac{\cos\frac{Nx}{2}\cos\frac{(N+1)x}{2}}{\cos\frac{x}{2}}.$$You can unify these e.g. as$$\frac{\sin\left(\frac{Nx}{2}+(1+(-1)^{N+1})\frac{\pi}{4}\right)\cos\frac{(N+1)x}{2}}{\cos\frac{x}{2}}.$$

• Just what I was looking for. Thanks a lot! Jun 20 '20 at 16:54

Hint:

Here is a fast method:

This alternating sum is the real part of

$$\sum_{k=1}^N (-1)^{k-1}\mathrm e^{ikx}=\mathrm e^{ix}\sum_{\ell=0}^{N-1} (-1)^{\ell}\mathrm e^{i\ell x}=\mathrm e^{ix}\frac{1-(-1)^N\mathrm e^{iNx}}{1+\mathrm e^{ix}}.$$ Now in the numerator of the fraction, factor out $$\:\mathrm e^{\tfrac{iN}2}$$, and in the denominator, $$\:\mathrm e^{\tfrac{ix}2}$$. Can you proceed?

• Not quite: your $1+e^{iNx}$ should be $1-(-e^{ix})^N$.
– J.G.
Jun 20 '20 at 9:37
• @J.G.: Right – I had the case $N$ odd in mind. Thank you for pointing it! Jun 20 '20 at 9:41