Closed form for $\int_{0}^{\pi/2}x\cos^n x \ dx$, $n\in\mathbb{N}$ Closed form for the definite integral $$I(n)=\int_{0}^{\pi/2}x\cos^n x \ dx$$ where $n\in\mathbb{N}$.
I tried using $\int_{0}^a f(x)\ dx= \int_{0}^a f(a-x)\ dx$ to get $$I(n)= \int_{0}^{\pi/2}\left(\frac{\pi}{2}-x\right)\sin^n x \ dx$$
So we have $$I(n)=\frac{\pi}{2^2}\frac{\Gamma(\frac{n+1}{2})\Gamma(1/2)}{\Gamma(\frac{n+2}{2})} -\int_{0}^{\pi/2}x\sin^n x \ dx$$
 A: Utilize the expansions
\begin{align}
&\cos^{2m}x= \frac1{2^{2m}}\binom {2m}{m}+\frac1{2^{2m-1}}\sum_{k=1}^{m} \binom {2m}{m-k} \cos2kx\\
&\cos^{2m+1}x= \frac1{2^{2m}}\sum_{k=0}^{m} \binom {2m+1}{m-k} \cos(2k+1)x\\
\end{align}
and the results
\begin{align}
&\int_0^{\pi/2}x\cos2mx\ dx= \frac{(-1)^m-1}{(2m)^2}\\
&\int_0^{\pi/2}x\cos(2m+1)x\ dx= \frac{\frac\pi2(2m+1)(-1)^m-1}{(2m+1)^2}
\end{align}
to obtain
\begin{align}
&\int_0^{\pi/2}x\cos^{2m}xdx
= \frac{\pi^2}{2^{2m+3}}\binom {2m}{m}+\frac1{2^{2m-1}}\sum_{k=1}^m \binom {2m}{m-k} \frac{(-1)^{k}-1}{(2k)^2}\\
&\int_0^{\pi/2}x\cos^{2m+1}x\ dx
=\frac1{2^{2m}}\sum_{k=0}^{m} \binom {2m+1}{m-k} \frac{\frac\pi2(2k+1)(-1)^k-1}{(2k+1)^2}\\
\end{align}
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{\mc}[1]{\mathcal{#1}}
 \newcommand{\mrm}[1]{\mathrm{#1}}
 \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{\totald}[3][]{\frac{\mathrm{d}^{#1} #2}{\mathrm{d} #3^{#1}}}
 \newcommand{\verts}[1]{\left\vert\,{#1}\,\right\vert}$
$\ds{\bbox[5px,#ffd]{}}$
\begin{align}
& \left.\rule{0pt}{5mm}{\tt I}\pars{n}
\right\vert_{n\ \in\ \mathbb{N}_{\,n\ \geq\ 0}} \equiv \color{#44f}{\int_{0}^{\pi/2}x\cos^{n}\pars{x}\,\dd x}
{\Large\ :\, ?}
\\[3mm] &
\left\{\begin{array}{rcl}
\ds{{\tt I}\pars{0}} & \ds{=} & \ds{\pi^{2} \over 8}
\\
\ds{{\tt I}\pars{1}} & \ds{=} & \ds{{\pi \over 2} - 1}
\end{array}\right.
\end{align}

\begin{align}
& \left.{\tt I}\pars{n}
\right\vert_{n\ \in\ \mathbb{N}_{\,\geq\ 2}}\,\,\, =
\int_{0}^{\pi/2}
\bracks{x\cos^{n - 1\,}\pars{x}}\cos\pars{x}\,\dd x
\\[5mm] \stackrel{\rm IBP}{=}\ &
-\ \overbrace{\int_{0}^{\pi/2}\sin\pars{x}\cos^{n - 1\,}\pars{x}\,\dd x}^{\ds{1/n}}
\\[2mm] & \ -
\int_{0}^{\pi/2}\sin\pars{x}x\pars{n - 1}\cos^{n - 2\,}\pars{x}
\bracks{-\sin\pars{x}}\,\dd x
\\[5mm] = & \
-{1 \over n}\ +\ \pars{n - 1}\
\overbrace{\int_{0}^{\pi/2}x\cos^{n - 2\,}\pars{x}
\,\dd x}^{\ds{{\tt I}\pars{n - 2}}}
\\[2mm] & \
-\pars{n - 1}\ \overbrace{\int_{0}^{\pi/2}x\cos^{n}\pars{x}
\,\dd x}^{\ds{{\tt I}\pars{n}}}
\\[5mm] & \!\!\!\!\!
\bbx{\color{#44f}{\left\{\begin{array}{rcl}
\ds{{\tt I}\pars{n}} & \ds{=} &
\ds{-\, {1 \over n^{2}} +
{n - 1 \over n}{\tt I}\pars{n - 2}}
\\[1mm] 
&&\ds{\color{black}{\pars{~n = 2,3,4,\ldots~}}}
\\[3mm]
\ds{{\tt I}\pars{0}} & \ds{=} & \ds{\pi^{2} \over 8}
\\[1mm]
\ds{{\tt I}\pars{1}} & \ds{=} & \ds{{\pi \over 2} - 1}
\end{array}\right.}} \\ &  
\end{align}
