TITLE: About the integral $\int_0^{\pi/2} \cos^n(x)\cos(nx) \;dx$ and $\int_0^{\pi/2} \cos^n(x)\sin(nx) \;dx$.
QUESTION [9 upvotes]: About the integral $\displaystyle\int_0^{\pi/2}\cos^n{x}\cos{nx} dx$ and $\displaystyle\int_0^{\pi/2} \cos^n{x}\sin{nx} dx$. The value of the first one contains $\pi$, However, I tried to calculate them by integrating by parts as follows.

Let $I(m,n)$ denote the integral $\displaystyle\int_0^{\pi/2} \cos^m{x}\cos{nx} dx$, we have 
$$
 \begin{split}
I(m,n)&=\displaystyle\int_0^{\pi/2} \cos^m{x}\cos{nx}\,dx=\dfrac{1}{n}\displaystyle\int_0^{\pi/2} \cos^m{x}\,d(\sin{nx})\\
&=\dfrac{1}{n}\cos^m{x}\sin{nx}\biggr|_0^{\pi/2}-\dfrac{m}{n}\displaystyle\int_0^{\pi/2} \sin{nx}\cos^{m-1}{x}\sin{x}\,dx\\
&=-\dfrac{m}{n}\displaystyle\int_0^{\pi/2} \sin{nx}\cos^{m-1}{x}\sin{x}\,dx\\
&=\dfrac{m}{n^2}\displaystyle\int_0^{\pi/2} \cos^{m-1}{x}\sin{x}\,d(\cos{nx})\\
&=\dfrac{m}{n^2}\cos^{m-1}{x}\sin{x}\cos^{nx}\biggr|_0^{\pi/2}-\dfrac{m}{n^2}\displaystyle\int_0^{\pi/2} \cos{nx}\,d(\cos^{m-1}{x}\sin{x})\\
&=-\dfrac{m}{n^2}\displaystyle\int_0^{\pi/2}\cos{nx}(\cos^m{x}+(m-1)\cos^{m-2}{x}\sin^2{x})\,dx\\
&=-\dfrac{m}{n^2}\displaystyle\int_0^{\pi/2} \cos{nx}\cos^m{x}\,d{x}-\dfrac{m(m-1)}{n^2}\displaystyle\int_0^{\pi/2} (1-\cos^2{x})\cos^{m-2}{x}\cos{nx}\,d{x}\\
&=\dfrac{m(m-2)}{n^2}\displaystyle\int_0^{\pi/2} \cos{nx}\cos^{m}{x}\,d{x}-\dfrac{m(m-1)}{n^2}\displaystyle\int_0^{\pi/2} \cos^{n-2}{x}\cos{nx}\,d{x}\\
&=\dfrac{m(m-2)}{n^2}I(m,n)-\dfrac{m(m-1)}{n^2}I(m-2,n),
\end{split}, 
$$
That is,
$$I(m,n)=-\dfrac{m(m-1)}{n^2-m^2+2m}I(m-2,n),$$
Then we can calculate $I(m,n)$ by calculating $I(0,n)$ and $I(1,n)$. I can't see where $\pi$ occurs.
Or I'm on the wrong way... ? I don't know. Anyone can help me?

REPLY [8 votes]: Maybe nice to have an alternative way to find the integral. 
Define $A_n, I_n$ and $J_n$ as follows: $$A_n:=\int^{\pi/2}_0 \cos^n(x) e^{inx}\,dx$$
$$I_n:=\int^{\pi/2}_0 \cos^n(x)\cos(nx)\,dx , \ \ \  \ \ \ J_n:=\int^{\pi/2}_0 \cos^n(x)\sin(nx)\,dx  $$
This means that $I_n = \Re A_n$ and $J_n=\Im A_n$. So we only have to find $A_n$. 
Using $\cos(x) = \frac 1 2 \left( e^{ix}+e^{-ix}\right)$ together with the Binomial Theorem one gets
\begin{align}
A_n &= \int^{\pi/2}_0 \frac 1{2^n}\left( e^{ix}+e^{-ix} \right)^n e^{inx}\,dx \\
&= \int^{\pi/2}_0 \frac 1{2^n} \sum_{k=0}^n \binom{n}{k} e^{i2kx} \,dx\\
&= \frac 1{2^n} \frac{\pi}{2}+ \frac 1{2^n}\sum_{k=1}^n \binom{n}{k} \int^{\pi/2}_0 e^{i2kx}\,dx\\
&=\frac {\pi}{2^{n+1}} + \frac 1{2^n}\sum_{k=1}^n \binom{n}{k} \frac{1}{i2k} \left( e^{ik\pi}-1\right)\\
&=\frac {\pi}{2^{n+1}} + \frac 1{2^n}\sum_{k=1}^n \binom{n}{k} \frac{1}{i2k} \left( (-1)^k-1\right)\\
&=\frac {\pi}{2^{n+1}} +i \frac 1{2^{n}}\sum_{k=0}^{\lfloor (n-1)/2 \rfloor} \binom{n}{2k+1} \frac{1}{2k+1} \\
\end{align}
Hence:
\begin{align}
I_n = \frac{\pi}{2^{n+1}}, \ \  \ \ \ J_n = \frac 1{2^{n}}\sum_{k=0}^{\lfloor (n-1)/2 \rfloor} \binom{n}{2k+1} \frac{1}{2k+1}
\end{align}
I don't know if a nice closed form for $J_n$ exists...