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!
 A: 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}
A: With \begin{align}
&\cos^{2m}x =\frac{1}{2^{2m}}\binom{2m}{m}+\frac{1}{2^{2m-1}}\sum_{k=1}^{m}\binom{2m}{m-k}\cos(2kx) \\
&\cos^{2m+1}x =\frac{1}{2^{2m}}\sum_{k=0}^{m}\binom{2m+1}{m-k}\cos[(2k+1)x]\\
\end{align}
integrate the 4 odd-even combinations below
\begin{align}
 &\int_{-\pi}^\pi \! \cos [(2j +1)x ]\cos^{2m}x \ {d}x =0\\
&\int_{-\pi}^\pi \! \cos (2jx) \cos^{2m}x \ {d}x
= \frac{ \binom{2m}{m-j} }{2^{2m-1}}\int_{-\pi}^\pi \! \cos^2(2jx)dx= \frac{\pi  \binom{2m}{m-j} }{2^{2m-1}} \\
 &\int_{-\pi}^\pi \! \cos (2jx )\cos^{2m+1}x \ {d}x =0\\
 &\int_{-\pi}^\pi \! \cos [(2j +1)x ]\cos^{2m+1}x \ {d}x 
= \frac{\binom{2m+1}{m-j}}{2^{2m}} \int_{-\pi}^\pi \! \cos^2[(2j+1)x]dx= \frac{\pi \binom{2m+1}{m-j}}{2^{2m}} \\
\end{align}
A: $$\begin{align} 2^n \cos^n x &= \left(e^{ix} + e^{-ix}\right)^n\\
&= e^{inx} + {n \choose 1}e^{i(n-2)x} + {n \choose 2}e^{i(n-4)x}+ \cdots+{n \choose 2}e^{-i(n-4)x}+{n \choose 1}e^{-i(n-2)x} +  e^{-inx}\\
&=2\cos nx+ 2{n \choose 1}\cos(n-2)x+2{n \choose 2}\cos(n - 4)x + \cdots  
 \end{align}$$
multiplying by $\cos kx,$ we have 
$$\begin{align}2^n \cos^n x\cos kx &= 2\cos nx\cos kx+ 2{n \choose 1}\cos(n-2)x\cos kx+{n \choose 2}\cos(n - 4)x\cos kx + \cdots \\
&=\cos(n+k)x +\cos(n-k)x+{n\choose 1}\left(\cos(n-2+k)x -\cos(n-2-k)x\right)\\ &+{n\choose 2}\left(\cos(n-4+k)x -\cos(n-4-k)x\right) +\cdots
\end{align}$$
only contribution to $\int_{-\pi}^{\pi} 2^n \cos^n x\cos kx\, dx$  are $2\pi{n \choose j}$ with $j = \frac{n+k}2$ and $-2\pi{n\choose j}$ with $j = \frac{n-k}2$ therefore $$\int_{-\pi}^{\pi} 2^n \cos^n x\cos kx\, dx = 2\pi\left({n\choose {\frac{n+k}2}} - {n\choose {\frac{n-k}2}}\right)$$
A: $\newcommand{\bbx}[1]{\,\bbox[15px,border:1px groove navy]{\displaystyle{#1}}\,}
 \newcommand{\braces}[1]{\left\lbrace\,{#1}\,\right\rbrace}
 \newcommand{\bracks}[1]{\left\lbrack\,{#1}\,\right\rbrack}
 \newcommand{\dd}{\mathrm{d}}
 \newcommand{\ds}[1]{{\displaystyle #1}}
 \newcommand{\expo}[1]{\,\mathrm{e}^{#1}\,}
 \newcommand{\ic}{\mathrm{i}}
 \newcommand{\on}[1]{\operatorname{#1}}
 \newcommand{\pars}[1]{\left(\,{#1}\,\right)}
 \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}}
 \newcommand{\root}[2][]{\,\sqrt[#1]{\,{#2}\,}\,}
 \newcommand{\sr}[2]{\,\,\,\stackrel{{#1}}{{#2}}\,\,\,}
 \newcommand{\totald}[3][]{\frac{\mathrm{d}^{#1} #2}{\mathrm{d} #3^{#1}}}
 \newcommand{\verts}[1]{\left\vert\,{#1}\,\right\vert}$
With $\ds{k = 0, 1, \ldots, \pars{n - 1}}$ and
$\ds{n \in \mathbb{N}}$:
\begin{align}
& \color{#44f}{\int_{-\pi}^{\pi}\cos\pars{kx}\cos^{n}\pars{x}
\,\dd x} =
\Re\int_{-\pi}^{\pi}\expo{\ic kx}\cos^{n}\pars{x}\,\dd x
\\[5mm] = & \
\Re\oint_{\verts{z}\ =\ 1}\
z^{k}\pars{z + 1/z \over 2}^{n}\,{\dd z \over \ic z} =
{1 \over 2^{n}}\,\Im\oint_{\verts{z}\ =\ 1}\
{\pars{1 + z^{2}}^{n} \over z^{n - k + 1}}\,\dd z
\\[5mm] = & \
{1 \over 2^{n}}\,\Im\sum_{\ell = 0}^{n}{n \choose \ell}\oint_{\verts{z}\ =\ 1}\,\,\,
{\dd z \over z^{n - k - 2\ell + 1}\,\,\,}
\\[5mm] = & \
{1 \over 2^{n}}\,\Im\sum_{\ell = 0}^{n}{n \choose \ell} 
2\pi\ic\,\delta_{n - k - 2\ell - 1,1}\rule{3mm}{0pt} =
{\pi \over 2^{n - 1}}
\sum_{\ell = 0}^{n}{n \choose \ell} 
\delta_{\ell,\pars{n - k}/2}
\\[5mm] = & \
{\pi \over 2^{n - 1}}
{n \choose \pars{n - k}/2}\bracks{\pars{n - k}\ even}
\end{align}
The last bracket is an Iverson Bracket.
