Answer to some trigonometry series I have  two series as bellow 
$$\frac{2}{N}\sum_{n=0}^{N-1}\cos^2(\frac{2\pi n(l-q)}{N})    \quad l\neq q \quad(1)$$ 
$$ \sum_{q=0}^{N-1}cos(\frac{2\pi nq}{N})cos(\frac{2\pi rq}{N}) \quad n\neq r \quad (2)$$
Where $l$, $q$, $r$, $n$ and $N$ are integers. I have computed the two series in MATLAB. The first one is equal to $1$ and the second one is zero. But I cannot prove this analytically. Can anyone help me understand why (1) equals $1$ and (2) equals zero?
Thanks in advance
 A: Express all trigonometric terms as complex exponentials and use the fact that the sum of all nth roots of unity is zero.
That is, write
$\cos^2\left(\frac{2\pi n(l-q)}{N}\right) = \left(\frac{e^{i\frac{2\pi n(l-q)}{N}} + e^{-i\frac{2\pi n(l-q)}{N}}}{2}\right)^2$
and
$\cos\left(\frac{2\pi nq}{N}\right)\cos\left(\frac{2\pi nr}{N}\right) = \left(\frac{e^{i\frac{2\pi nq}{N}} + e^{-i\frac{2\pi nq}{N}}}{2}\right)\left(\frac{e^{i\frac{2\pi nr}{N}} + e^{-i\frac{2\pi nr}{N}}}{2}\right)$
You'll find yourself evaluating expressions of the form $\sum_{q=1}^{N-1} e^{i2\pi \alpha q/N}$, where $\alpha$ is an integer less than $N$. Using the fact that $e^{i2\pi} =1$, you'll have that $\left(e^{i2\pi \alpha/N}\right)^N = 1$. Therefore, using the fact that
$$
1 + x + x^2 + \cdots + x^{N-1} = \frac{x^N - 1}{x - 1},
$$
for $x \ne 1$,
you'll find that
$$
\sum_{q = 0}^{N-1} e^{i2\pi \alpha q/N} = 0.
$$
However, if $\alpha = N$, then $e^{i2\pi \alpha q/N} =1$ for all $q$, and thus
$$
\sum_{q = 0}^{N-1} e^{i2\pi \alpha q/N} = N.
$$
A: For Reference, I am putting two formulas I've used in the solution of these questions : 
(Sum of sines and cosines with angle are in A.P.)

$\displaystyle \sum_{k=0}^{n} \sin(k\beta) = \dfrac{\sin \dfrac{n\beta}{2}}{\sin \dfrac{\beta}{2}} \cdot \sin \left [ (n+1)\dfrac{\beta}{2} \right]$
$\displaystyle \sum_{k=0}^{n} \cos(k\beta) = \dfrac{\sin \dfrac{n\beta}{2}}{\sin \dfrac{\beta}{2}} \cdot \cos \left [ (n+1)\dfrac{\beta}{2} \right]$

1st Question - Partial Solution::
$\displaystyle  \begin{aligned} \dfrac{2}{N}\sum_{n=0}^{N-1}\cos^2 \left (\dfrac{2\pi n(l-q)}{N} \right) &= \dfrac{2}{N} \sum_{n=0}^{N-1} \left [ \dfrac{1 + \cos \dfrac{4 \pi n(l-q)}{N}}{2}  \right] \\ \\  &= \dfrac{2}{N}  \left [\dfrac{N-1}{2} + \dfrac {\displaystyle \sum_{n=0}^{N-1} \cos \dfrac{4 \pi n(l-q)}{N}}{2}  \right] \\ \\ &= \dfrac{2}{N}  \left [\dfrac{N-1}{2} +  \dfrac{\sin \dfrac{2 \pi (l-q)(N-1)}{N}}{2\sin \dfrac{2 \pi (l-q)}{N}} \cdot \cos \dfrac{2 \pi (l-q)N}{N} \right] \\ \\ &= \dfrac{2}{N}  \left [\dfrac{N-1}{2} +  \dfrac{1}{2}  \right] =1 .\end{aligned} $ 
(try to understand the last step here. )
2nd Question -- Hint::
$\begin{aligned} \sum_{q=0}^{N-1}cos(\frac{2\pi nq}{N})cos(\frac{2\pi rq}{N}) &= \dfrac{1}{2}\sum_{q=0}^{N-1} 2cos(\frac{2\pi nq}{N})cos(\frac{2\pi rq}{N}) \\ &= \dfrac{1}{2}\sum_{q=0}^{N-1} \sin \left (\frac{2\pi (n+r)q}{N} \right) + \sin \left(\frac{2\pi (n-r)q}{N} \right)\end{aligned}$.
