Integrate sin(nx)sin(mx) from 0 to 2$\pi$ using residuals I need to use the residues integration method to calculate the following integral:
$\int_0^{2\pi} sin(nx)sin(mx)dx$ where m and n are positive whole numbers.
I know that I need to transform the sinus into its exponential form then substitute for $z=e^{ix}$ and do a change of variable in the integral, then use the theorem saying that the integral along a closed curve is $2\pi i$ times the sum of the residues of all the singularities inside the curve. 
However, I do not manage to get the right answer, and for the case m=n I get $\pi/2$ instead of $\pi$.
 A: The trick for trigonometric integrals:
$$
z = e^{ix}\implies\sin(nx) =
\frac12(e^{inx} − e^{−inx}) = \frac12(z^n - z^{-n})
\qquad dz = iz\,dx
$$
$$
\int_{0}^{2\pi}\sin(nx)\sin(mx)\,dx =
\frac14\int_{|z|=1}(z^n - z^{-n})(z^m - z^{-m})\frac1{iz}\,dz = 
$$
$$
\frac1{4i}\int_{|z|=1}(z^{m-n-1} + z^{n-m-1} - z^{m+n-1} - z^{-m-n-1})\,dz = \cdots
$$
In your problematic case:
$$
m = n\ne 0\implies
z^{m-n-1} = z^{n-m-1} = z^{-1}, z^{m+n-1}\ne z^{-1},
z^{-m-n-1}\ne z^{-1},
$$
and the integral is $\frac{2\cdot2\pi i}{4i} = \pi$.
A: \begin{align*}
\int_{0}^{2\pi}\sin(nx)\sin(mx)dx&=-\dfrac{1}{4}\int_{0}^{2\pi}(e^{inx}-e^{-inx})(e^{imx}-e^{-imx})dx\\
&=-\dfrac{1}{4}\int_{0}^{2\pi}(e^{i(m+n)x}-e^{-i(m+n)x}-e^{-i(n-m)x}-e^{-i(m-n)x})dx\\
&=-\dfrac{1}{4}\int_{0}^{2\pi}(-e^{-i(n-m)x}-e^{-i(m-n)x})dx\\
&=-\dfrac{1}{4}\delta_{m,n}(-2\pi-2\pi)\\
&=\delta_{m,n}\pi.
\end{align*}
A: Hints:


*

*If $f(a-x)=f(x)$ on $[0,a]$, then $\int_0^a f(x)~\mathrm dx=\int_0^a f(a-x)~\mathrm dx$

*If $f(2a-x)=f(x)$ on $[0,2a]$, then $\int_0^{2a} f(x)~\mathrm dx=2\int_0^a f(x)~\mathrm dx$

*Suppose $m=n=k=2^rs$ where $2\not\mid s$. Can you show that $$\int_0^{2\pi}\sin^2(kx)~\mathrm dx=2^{r+1}\int\limits_0^{\pi/2^r}\sin^2(kx)~\mathrm dx=2^{r+1}\cdot\frac{\dfrac\pi{2^r}-0}2=2^{r+1}\cdot\frac\pi{2^{r+1}}=\pi$$
