TITLE: Computing the indefinite integral $\int x^n \sin x\,dx$
QUESTION [8 upvotes]: $\newcommand{\term}[3]{
  \sum_{k=0}^{\lfloor #1/2 \rfloor} (-1)^{#2} x^{#3} \frac{n!}{(#3)!}
}$
I am trying to prove that for $n \in\mathbb N$,
$$
\int x^n \sin x \, dx
= \cos x \term{n}{k+1}{n-2k}
+ \sin x \term{(n-1)}{k}{n-2k-1}
$$
I started with differentiation, and this is what I got:
If we define $f(x)$ as
$$
f(x)
= \cos x \term{n}{k+1}{n-2k}
+ \sin x \term{n-1}{k}{n-2k-1}
$$
then we have
$$
\begin{align*}
f’(x)
&= \cos x \term{n}{k+1}{n-2k-1}
 - \sin x \term{n}{k+1}{n-2k} \\
&\qquad
 + \sin x \term{(n-1)}{k}{n-2k-2}
 + \cos x \term{(n-1)}{k}{n-2k-1} \\[8pt]
&= \cos x \left[
   \term{n}{k+1}{n-2k-1}
 + \term{(n-1)}{k}{n-2k-1}
\right] \\
&\qquad
 + \sin x \left[
   \term{(n-1)}{k}{n-2k-2}
 - \term{n}{k+1}{n-2k}
\right]
\end{align*}
$$
I don't know how to go on, because of the different limits of the sum with $\lfloor{n/2}\rfloor$ and $\lfloor{(n-1)/2}\rfloor$.

REPLY [4 votes]: Well.. I think I have a different way
$$ \int_a^b e^{izt} dz = \frac{e^{izt} }{it} |_{z=a}^{z=b}$$
Differentiate both sides with $t$ n times (*) and apply leibniz product rule(**) and some rearranging::
$$ \int_a^b z^n e^{izt} dz = \frac{1}{i^{n+1}}  \sum_{k=0}^n \frac{1}{t^{k+1}} \binom{n}{k} (-1)^k k! (iz)^{n-k} e^{izt} |_{z=a}^{z=b}$$
Simplfying and putting t=1:
$$ \int_a^b z^n e^{iz} dz= \sum_{k=0}^n \frac{n!}{(n-k)!} (i)^{k-1} z^{n-k} e^{iz} |_{z=a}^{z=b}$$
Let's see if this formula really works, sub in $a=0$ and $b= \frac{\pi}{2}$ and $n=2$:
$$ \int_0^{\frac{\pi}{2}} z^2 e^{iz} dz= \sum_{k=0}^2 \frac{2!}{(2-k)!} (i)^{k-1} z^{2-k} e^{iz} |_{z=0}^{z= \frac{\pi}{2}}= 2!e^{iz} \left[  \frac{-iz^2}{2!} + \frac{z}{1!} + \frac{i}{0!}\right]_{0}^{\frac{\pi}{2} }=e^{iz} \left[ 2i + 2z -iz^2  \right]_0^{\frac{\pi}{2} }= i(2i + \pi - i\frac{\pi^2}{4}) - (2i)=( \frac{\pi^2}{4} -2)+i(\pi -2) $$
Hence, by taking imaginary on both sides we get:
$$ \int_0^{\frac{\pi}{2} } z^2 sin(z) dz = \pi -2$$
And similar results for cosine :)
P.s: I nominate the above result to be called the trigonometric gamma function (incase this wasn't discovered before)
Oh btw I this also gives the results for $x^n sin(ax)$ :P
*: Feynman's trick
**: Leibniz product rule