<s>[INST] Definite integral of $x\sin^n x$ from $0$ to $\pi/2$ How to find
\begin{equation*}
\int_0^{\pi/2} x\sin^n x dx
\end{equation*}
where $n$ is a positive integer? I tried $y=x-\pi/4$ and that gives
\begin{equation*}
\frac{1}{2^{n/2}}\frac{\pi}{4}\int_{-\pi/4}^{\pi/4} (\sin y+\cos y)^n dy+\frac{1}{2^{n/2}}\int_{-\pi/4}^{\pi/4} y(\sin y+\cos y)^n dy.
\end{equation*}
Although some terms may be canceled, the summation of the others seems terrible.
Another method is integration by parts. Here I found the recurrence formula for $\sin^n x$:
Integrating $\int \sin^n{x} \ dx$
So the first step is to have
\begin{equation*}
\left.\left(-\frac{1}{n}x\cos x\sin^{n-1} x+\frac{n-1}{n}x\int \sin^{n-2} xdx\right)\right|_0^{\pi/2}-\int_0^{\pi/2}\left(-\frac{1}{n}\cos x\sin^{n-1} x+\frac{n-1}{n}\int_0^x \sin^{n-2} t dt\right)dx
\end{equation*}
the evaluations at $0$ and $\pi/2$ and the integral of $\cos x\sin^{n-1}x$ seem OK, but what about the second term? Any better method for this problem?
 [/INST] $I_0=\frac{\pi^2}8$ and $I_1=1$ and for $n\ge2$,
$$
\begin{align}
I_n
&=\int_0^{\pi/2}x\sin^n(x)\,\mathrm{d}x\tag1\\
&=-\int_0^{\pi/2}x\sin^{n-1}(x)\,\mathrm{d}\cos(x)\tag2\\
&=(n-1)\int_0^{\pi/2}x\cos^2(x)\sin^{n-2}(x)\,\mathrm{d}x+\int_0^{\pi/2}\cos(x)\sin^{n-1}(x)\,\mathrm{d}x\tag3\\
&=(n-1)\int_0^{\pi/2}x\sin^{n-2}(x)\,\mathrm{d}x-(n-1)I_n+\frac1n\tag5\\
&=\frac{n-1}nI_{n-2}+\frac1{n^2}\tag5\\
\end{align}
$$
Explanation:
$(2)$: prepare to integrate by parts
$(3)$: integrate by parts
$(4)$: $\cos^2(x)=1-\sin^2(x)$ and the $\sin^2(x)$ part replicates $I_n$
$(5)$: add $(n-1)I_n$ to both sides and divide by $n$  

Using $I_0$ and $(5)$, we can compute $I_{2n}$:
$$
\begin{align}
I_{2n}
&=\frac{(2n-1)!!}{(2n)!!}\left[\frac{\pi^2}8+\sum_{k=0}^{n-1}\frac{(2n-2k-2)!!}{(2n-2k-1)!!}\frac1{2n-2k}\right]\\
&=\frac{\binom{2n}{n}}{4^n}\left[\frac{\pi^2}8+\sum_{k=0}^{n-1}\frac{4^{n-k}}{\binom{2n-2k}{n-k}}\frac1{(2n-2k)^2}\right]
\end{align}
$$

Using $I_1$ and $(5)$, we can compute $I_{2n+1}$:
$$
\begin{align}
I_{2n+1}
&=\frac{(2n)!!}{(2n+1)!!}\left[1+\sum_{k=0}^{n-1}\frac{(2n-2k-1)!!}{(2n-2k)!!}\frac1{2n-2k+1}\right]\\
&=\frac1{2n+1}\frac{4^n}{\binom{2n}{n}}\left[1+\sum_{k=0}^{n-1}\frac{\binom{2n-2k}{n-k}}{4^{n-k}}\frac1{2n-2k+1}\right]
\end{align}
$$
</s>