
I encountered this integral while doing a heat equation problem in Advanced Calculus.
How does the person evaluate the integral involving
$$\int_0^\pi \sin x \cos (nx) \: dx $$
Can someone explain it to me in more detail?

I encountered this integral while doing a heat equation problem in Advanced Calculus.
How does the person evaluate the integral involving
$$\int_0^\pi \sin x \cos (nx) \: dx $$
Can someone explain it to me in more detail?
Copyright © 2021 JogjaFile Inc.
One may use the identity $$ 2\sin a \cos b = \sin(a+b)+\sin(a-b) $$ to write, for $n \neq\pm1$, $$ \begin{align} 2\int_0^\pi \sin x \cos (nx) \: dx &=\int_0^\pi \left(\sin( (1+n)x)+\sin( (1-n)x)\right) dx \\\\ &=\left[\frac {-\cos( (1+n)x)}{1+n}+ \frac {-\cos( (1-n)x)}{1-n}\right]_0^\pi\\\\ &=-\left(\frac {\cos( (1+n)\pi)}{1+n}+ \frac {\cos( (1-n)\pi)}{1-n}\right)+\left(\frac {1}{1+n}+ \frac {1}{1-n}\right)\\\\ &=\frac {(-1)^n}{n+1}-\frac {(-1)^n}{n-1}+\frac {1}{n+1}- \frac {1}{n-1} \\\\ &=\frac {2(-1)^n}{n^2-1}+\frac {2}{n^2-1} \end{align} $$ giving