Show that $\int_{-\pi}^\pi\sin mx\sin nx d x$ is 0 $m\neq n$ and $\pi$ if $m=n$ using integration by parts

First, since $\,\sin kx\,$ is an odd function, $\,\sin mx\sin nx\,$ is even, so

$$\int\limits_{-\pi}^\pi\sin mx\sin nx\,dx=2\int\limits_0^\pi\sin mx\sin nx\,dx$$

Now, by parts:

$$u=\sin mx\;,\;\;u'=m\cos mx\\v'=\sin nx\;,\;\;v=-\frac{1}{n}\cos nx$$

so

$$\text{J:}=2\int\limits_0^\pi\sin mx\sin nx\,dx=\stackrel{\text{this is zero}}{\overbrace{\left.-\frac{2}{n}\sin mx\cos nx\right|_0^\pi}}+\frac{2m}{n}\int\limits_0^\pi\cos mx\cos nx\,dx$$

Again, by parts:

$$u=\cos mx\;,\;\;u'=-m\sin mx\\v'=\cos nx\;,\;\;v=\frac{1}{n}\sin nx\;\;\;\Longrightarrow$$

$$\text{J}=\left.-\frac{2m}{n^2}\sin nx\cos mx\right|_0^\pi+\frac{2m^2}{n^2}\int\limits_0^\pi\sin mx\sin nx\,dx\Longrightarrow$$

$$\left(\frac{n^2-m^2}{n^2}\right)\text{J}=0\;,\;\text{and thus} \;n\neq m\Longrightarrow \text{J}\,=0\,$$

If $\,n=m\,$ , then after the line where J first appears we get

$$2\int\limits_0^\pi\sin mx\sin mx\,dx=2\int\limits_0^\pi\cos mx\cos mx\,dx\Longrightarrow$$ $$2\text{ J}\,=2\int\limits_0^\pi\left(\cos mx\cos mx+\sin mx\sin mx\right)\,dx=2\int\limits_0^\pi \cos[(m-m)x]\,dx=$$

$$=2\int\limits_0^\pi dx=2\pi\Longrightarrow\,\text{ J}\,=\pi$$

Addedd: Using the complex exponential:

$$\sin kx:=\frac{e^{ikx}-e^{-ikx}}{2i}\;,\;\;k,x\in\Bbb R\Longrightarrow$$

$$\text{ J}\,=2\int\limits_0^\pi\sin mx\sin nx\,dx=-\frac{1}{2}\int\limits_0^\pi\left(e^{imx}-e^{-imx}\right)\left(e^{inx}-e^{-inx}\right)dx=$$

$$-\frac{1}{2}\int\limits_0^\pi\left[\left(e^{ix(m+n)}+e^{-ix(m+n)}\right)-\left(e^{ix(m-n)}+e^{-ix(m-n)}\right)\right] dx=$$

$$=\int\limits_0^\pi\left(\cos(m-n)x-\cos(m+n)x\right)dx=$$

$$=\begin{cases}\int\limits_0^\pi(dx-\cos2mx)dx=\pi-\left.\frac{1}{2m}\sin 2mx\right|_0^\pi=\pi\;\;,\;\;\;\;m=n\\{}\\{}\\ \left.\left(\frac{1}{m-n}\sin(m-n)x-\frac{1}{m+n}\sin(m+n)x\right)\right|_0^\pi=0\;\;,\;\;\;\;m\neq n\end{cases}$$

Of course, the use of the complex exponential in this case is a lame excuse to "forget" the basic trigonometric identity we got here and get it in a rather easy way.


HINT:

We don't really need Integration by parts

We know, $$2\sin mx\sin nx=\cos(m-n)x-\cos(m+n)x$$

$$\cos(m-n)x-\cos(m+n)x=\begin{cases} 1-\cos2nx&\text{ if }m=n,\\ \cos2nx-1&\text{if }m+n=0. \end{cases} $$

Now use $\int\cos axdx=\frac{\sin ax}a$


Use $\sin nx = \frac{1}{2i}(e^{inx} - e^{-inx})$ to get:

\begin{align} \sin nx \sin mx &= -\frac{1}{4}\left(e^{inx} - e^{-inx}\left)\right(e^{imx} - e^{-imx}\right) \\ &= -\frac{1}{4}\left(e^{i(n+m)x} - e^{i(n-m)x} - e^{i(m-n)x} + e^{-i(n+m)x}\right) \end{align}

Thus:

\begin{align} I = \int_{-\pi}^\pi \sin nx \sin mx \,dx = -\frac{1}{4} &\left(\int_{-\pi}^\pi e^{i(n+m)x} \,dx - \int_{-\pi}^\pi e^{i(n-m)x} \,dx \right. \\ & \left. - \int_{-\pi}^\pi e^{i(m-n)x} \,dx + \int_{-\pi}^\pi e^{-i(n+m)x} \,dx\right) \end{align}

Note that: $$ \int_{-\pi}^\pi e^{ikx} \,dx = \begin{cases}0 &\text{ if } k \ne 0 \\ 2\pi & \text{ if } k = 0\end{cases} $$

This follows by direct computation.

Thus, if $n \ne m$ and $n \ne -m$, all integrals in $I$ are $0$.

If $n = m$, we have:

$$ I = -\frac{1}{4}(-2\pi -2\pi) = \pi $$

If $n = -m$, we have: $$ I = -\frac{1}{4}(2\pi + 2\pi) = -\pi $$

If you assume that $n, m \ge 0$, you can ignore the last case.