I'm starting with Fourier analysis and in the first chapter the following exercise is stated:
Prove that if $n,m \geq 1$, we have $\frac{1}{\pi} \int_{-\pi}^{\pi} \cos(nx) \cos(mx) dx$ equals $0$ if $n \neq m$ and equals $1$ if $n=m$.
The latter I've shown using the fact that $\cos^2(x)$=$\frac{1}{2}+\frac{1}{2}\cos(2x)$, that works just fine.
But I'm stuck at the first part, when $n \neq m$. I know it's pretty much basic calculus but I'm stuck all the same.
Let's do it by integration by parts (IPP). Let $n,m\geq 1$ with $n\neq m$; further, since we want to show the integral is equal to $0$, I'll omit the factor $\frac{1}{\pi}$. Then (coloring in red the factor I integrate, and blue the one I differentiate), $$\begin{align} \int_{-\pi}^\pi \color{red}{\cos nx}\color{blue}{\cos mx} dx &= \color{red}{\frac{1}{n}}[\color{red}{\sin nx}\color{blue}{\cos mx}]_{-\pi}^\pi- \frac{\color{blue}{-m}}{\color{red}{n}}\int_{-\pi}^\pi \color{red}{\sin nx}\color{blue}{\sin mx} dx\\ &= \frac{m}{n}\int_{-\pi}^\pi \sin nx\sin mx dx \tag{1} \end{align}$$ using the fact that $\sin k\pi = 0$ for every $k\in\mathbb{Z}$ to see that the first term cancels. Further, again by IPP, $$\begin{align} \int_{-\pi}^\pi \color{red}{\sin nx}\color{blue}{\sin mx} dx &= \frac{1}{n}[-\cos nx \sin mx] + \frac{m}{n}\int_{-\pi}^\pi \cos nx\cos mx dx \\ &= \frac{m}{n}\int_{-\pi}^\pi \cos nx\cos mx dx \tag{2} \end{align}$$ Combining (1) and (2), we get $$ \int_{-\pi}^\pi \cos nx\cos mx dx = \frac{m^2}{n^2}\int_{-\pi}^\pi \cos nx\cos mx dx \tag{3} $$ and since $\frac{m^2}{n^2} \neq 1$ since implies $$ \int_{-\pi}^\pi \cos nx\cos mx dx = 0\,.\tag{4} $$