Integral of a product of cosines with different arguments? Hello all I'm working through a guided proof of Plancherel's Theorem and am currently trying to determine why the the following integral gives the result it does:

$\int_{-a}^{a} cos(\frac{n\pi x}{a})cos(\frac{m\pi x}{a})dx = a\delta_{mn}, \ with\ m\ and\ n \in \mathbb{Z}$

I've invoked the property of exponentials to add the exponents when multiplying together to find that:

*

*$cos(\frac{n\pi x}{a})cos(\frac{m\pi x}{a})dx = [\frac{1}{2}(e^{i(\frac{n\pi x}{a})} + e^{-i(\frac{n\pi x}{a})})][\frac{1}{2}(e^{i(\frac{m\pi x}{a})} + e^{-i(\frac{m\pi x}{a})})] = \frac{1}{4}[e^{iN}e^{iM} + e^{-iN}e^{iM} + e^{iN}e^{-iM} + e^{-iN}e^{-iM}] = \frac{1}{4}[2e^{iN}e^{iM} + 2e^{-iN}e^{iM}] = \frac{1}{2}[e^{i(N+M)} + e^{-i(N+M)}] = cos[\frac{(n+m)\pi x}{a}]$

*

*where $N = \frac{n\pi x}{a}$ and $M$ defined similarly



*$\int_{-a}^{a} cos[\frac{(n+m)\pi x}{a}]dx = \frac{a}{(n+m)\pi} sin[\frac{(n+m)\pi x}{a}]|_{-a}^{a} = \frac{a}{(n+m)\pi}[sin((n+m)\pi) - sin(-(n+m)\pi)] = \frac{a}{(n+m)\pi}[sin((n+m)\pi) + sin((n+m)\pi)] = \frac{a}{(n+m)\pi}[2sin((n+m)\pi)]$

*

*Obviously here when $m = n$ we get $sin(k\cdot 2\pi)$ where $k = n = m \in \mathbb{Z}$ but that equals $0$, hardly something which would give us our delta function.



I must be missing something obvious or just plain doing something completely wrong. Any help in elucidating this integral's solution would be very much appreciated.
 A: $\newcommand{\d}{\,\mathrm{d}}$There are two ways to look at this. The first is to use: $$\cos(x)\cos(y)=\frac{1}{2}(\cos(x+y)+\cos(x-y))$$
So: $$\begin{align}\\I&=\int_{-a}^a\cos\frac{n\pi}{a}x\cos\frac{m\pi}{a}x\d x\\&=\frac{1}{2}\left(\int_{-a}^a\cos\frac{m+n}{a}\pi x\d x+\int_{-a}^a\cos\frac{m-n}{a}\pi x\d x\right)\\&\overset{1}{=}\frac{a}{2\pi}\left[\frac{1}{m+n}\sin\frac{m+n}{a}\pi x+\frac{1}{m-n}\sin\frac{m-n}{a}\pi x\right]_{-a}^a=0\\&\overset{2}{=}\frac{a}{2\pi}\left[\frac{1}{m+n}\sin\frac{m+n}{a}\pi x\right]_{-a}^a+\frac{1}{2}\int_{-a}^a1\d x=0+\frac{1}{2}2a=a\end{align}$$
Where cases $1,2$ were $m\neq n\wedge m\neq -n$ and $m=n$ respectively (the $m=-n$ case is identical).
The second is to use integration by parts twice (e.g. in the first function).
$$\begin{align}I&=\frac{a}{n\pi}[0]-\frac{a}{n\pi}\cdot\frac{-m\pi}{a}\int_{-a}^a\sin\frac{n\pi}{a}x\sin\frac{m\pi}{a}x\d x\\&=\frac{m}{n}\left[\frac{a}{n\pi}[0]-\frac{a}{n\pi}\cdot\frac{m\pi}{a}\int_{-a}^a(-1)\cos\frac{n\pi}{a}x\cos\frac{m\pi}{a}x\d x\right]\\&=\left(\frac{m}{n}\right)^2I\end{align}$$
With $m,n\neq0$ assumed (those cases are left for you to solve) and thus either $I=0$ or $m=n$; once you know $m=n$, solving for $I$ is not so hard.
Throughout this whole post I have been using the fact that $\sin\frac{k}{a}\pi x\Big|_{-a}^a=\sin k\pi-\sin(-k\pi)=0$ when $k$ is an integer.
A: First, note that the average value of $\cos^2$ across a period is always $1/2$, since it must be the same as the average value of $\sin^2$ (as it is just $\cos^2$ shifted over by half the period), and they sum to $1$. Therefore
$$\frac{1}{2a}\int_{-a}^a\cos^2\left(\frac{n\pi x}{a}\right)\,\mathrm{d}x=\frac12.$$
On the other hand, if $m\neq n$ then let $\theta=\pi x/a$ so that $\theta$ runs from $-\pi$ to $\pi$. Consider the fact that $$\int_{-\pi}^\pi e^{im\theta}e^{in\theta}\,\mathrm{d}\theta=\int_{-\pi}^\pi e^{i(m+n)\theta}\,\mathrm{d}\theta =0$$
since we are integrating a complex differentiable function with the same beginning and end points. Now, $\cos(m\theta)=\frac12(\exp(im\theta)+\exp(-im\theta))$ and similarly for $\cos(n\theta)$. Using this, you should be able to complete the rest of the problem.
