<s>[INST] Evaluate $\int_{-\pi}^\pi \! \cos(kx)\cos^n(x) \, \mathrm{d}x$ My question is:

Evaluate $$\int_{-\pi}^\pi \! \cos(kx)\cos^n(x) \, \mathrm{d}x$$ for $k=0,1,...,(n-1)$ and $n \in \mathbb{N}$.

I've tried integration by parts but without much success. Any help/trick for this integral? Thanks!
 [/INST] For every $n\in \mathbb{N}$ we have:
\begin{eqnarray}
\cos(kx)\cos^n(x)&=&\frac{e^{ikx}+e^{-ikx}}{2}\left(\frac{e^{ix}+e^{-ix}}{2}\right)^n\\
&=&\frac{e^{ikx}+e^{-ikx}}{2^{n+1}}\sum_{p=0}^n{n\choose p}e^{i(n-p)x}e^{-ipx}\\
&=&\frac{1}{2^{n+1}}\sum_{p=0}^n{n\choose p}\left[e^{i(n+k-2p)x}+e^{i(n-k-2p)x}\right]\\
&=&\frac{1}{2^{n+1}}\sum_{p=0}^n{n\choose p}e^{i(n+k-2p)x}+\frac{1}{2^{n+1}}\sum_{p=0}^n{n\choose p}e^{i(n-k-2p)x}\\
&=&\frac{1}{2^{n+1}}\sum_{p=0}^n{n\choose p}e^{i(n+k-2p)x}+\frac{1}{2^{n+1}}\sum_{p=0}^n{n\choose n-p}e^{i[n-k-2(n-p)]x}\\
&=&\frac{1}{2^{n+1}}\sum_{p=0}^n{n\choose p}e^{i(n+k-2p)x}+\frac{1}{2^{n+1}}\sum_{p=0}^n{n\choose p}e^{i(-n-k+2p)x}\\
&=&\frac{1}{2^{n+1}}\sum_{p=0}^n{n\choose p}e^{i(n+k-2p)x}+\frac{1}{2^{n+1}}\sum_{p=0}^n{n\choose p}e^{-i(n+k-2p)x}\\
&=&\frac{1}{2^n}\sum_{p=0}^n{n\choose p}\frac{e^{i(n+k-2p)x}+e^{-i(n+k-2p)x}}{2}\\
&=&\frac{1}{2^n}\sum_{p=0}^n{n\choose p}\cos(n+k-2p)x
\end{eqnarray}
Case 1: $n+k$ is even. Let
$$
A(k,n)=\{0\le p\le n:\, 2p\ne n+k\}.
$$
We have
\begin{eqnarray}
\int_{-\pi}^\pi\cos(kx)\cos^n(x)\,d&=&2\int_0^\pi\cos(kx)\cos^n(x)\,dx=\frac{1}{2^{n-1}}\sum_{p=0}^n{n\choose p}\int_0^\pi\cos(n+k-2p)x\,dx\\
&=&\frac{\pi}{2^{n-1}}{n\choose \frac{n+k}{2}}+\frac{1}{2^{n-1}}\sum_{p \in A(k,n)}{n\choose p}\int_0^\pi \cos(n+k-2p)x\,dx\\
&=&\frac{\pi}{2^{n-1}}{n\choose \frac{n+k}{2}}+\frac{1}{2^{n-1}}\sum_{p\in A(k,n)}{n\choose p}\left[\frac{\sin(n+k-2p)x}{n+k-2p}\right]_0^\pi\\
&=&\frac{\pi}{2^{n-1}}{n\choose \frac{n+k}{2}}.
\end{eqnarray}
Case 2: $n+k$ is odd. We have:
\begin{eqnarray}
\int_{-\pi}^\pi\cos(kx)\cos^n(x)\,d&=&2\int_0^\pi\cos(kx)\cos^n(x)\,dx=\frac{1}{2^{n-1}}\sum_{p=0}^n{n\choose p}\int_0^\pi\cos(n+k-2p)x\,dx\\
&=&\frac{1}{2^{n-1}}\sum_{p=0}^n{n\choose p}\left[\frac{\sin(n+k-2p)x}{n+k-2p}\right]_0^\pi\\
&=&0.
\end{eqnarray}
</s>