Show that $\displaystyle\int_{-\pi}^\pi\sin mx\sin nx d x=\begin{cases}0&\text{if }m\neq n,\\\pi&\text{if }m=n\end{cases}$ using integration by parts

Show that
$$\int_{-\pi}^{\pi}\sin{mx}\,\sin{nx}\, d x =\begin{cases}
0&\text{if }m\neq n,\\
\pi&\text{if }m=n.
\end{cases}$$
by using integration by parts.

I’ve done the following, but I’m not sure if I went the wrong direction, if I messed up some calculation, or if I’m almost there and just can’t see what to do next…

$$\int_{-\pi}^{\pi}\sin{mx}\,\sin{nx} \, d x=-\left(\frac{n}{n^2-m}\right)\sin{mx}\cos{nx}+\left(\frac{m}{n^2-m}\right)\cos{mx}\sin{nx}+C$$

$$=-2\left(\frac{n}{n^2-m}\right)\sin{m\pi}\cos{n\pi}+2\left(\frac{m}{n^2-m}\right)\cos{m\pi}\sin{n\pi}$$

Now … I figure that if $n=m$, then I can just as well replace them all with a 3rd variable… say $z$…

$$=-2\left(\frac{z}{z^2-z}\right)\sin{z\pi}\cos{z\pi}+2\left(\frac{z}{z^2-z}\right)\cos{z\pi}\sin{z\pi}$$

Wouldn’t that equal 0? Or am I completely mistaken?


Addition:

By following the suggestions below and using the product-to-sum forumulas, I got the following:

$$\frac{1}{2}\int\cos{((n-m)x)}\ dx-\frac{1}{2}\int\cos{((n+m)x)}\ dx=\frac{\sin{((n-m)x)}}{2(n-m)}-\frac{\sin{((n+m)x)}}{2(n+m)}$$

So now if $n=m$, then the first quotient will end up dividing by 0…

Solutions Collecting From Web of "Show that $\displaystyle\int_{-\pi}^\pi\sin mx\sin nx d x=\begin{cases}0&\text{if }m\neq n,\\\pi&\text{if }m=n\end{cases}$ using integration by parts"

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$

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.

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.