# indefinite integral of $x^n \cdot \sin(x)$ proof

I am trying to prove $$\int x^n\sin x\,dx=\sum_{k=0}^{\lfloor{n/2}\rfloor}(-1)^{k+1}x^{n-2k}{n!\over(n-2k)!}\cos x\\+\sum_{k=0}^{\lfloor{(n-1)/2}\rfloor}(-1)^kx^{n-2k-1}{n!\over(n-2k-1)!}\sin x$$

with $n\in \Bbb N$.

I started with differentiation and this is what I got:

http://i.stack.imgur.com/S6KAf.png

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$

-

Instead, let's use induction and (iterated) integration by parts. (Note that there should be a "${}+C$ " in that formula, but I'm not going to worry about that.)

First, let's take any $n\ge 1$ and integrate $\int x^n\sin x\,dx$ by parts to see what happens. By the LIATE Rule, we should take $u_1=x^n$ and $dv_1=\sin x\,dx$, giving us $du_1=nx^{n-1}\,dx$ and $v_1=-\cos x$. Then $$\int x^n\sin x\,dx=\int u_1\,dv_1=u_1v_1-\int v_1\,du_1=-x^n\cos x+n\int x^{n-1}\cos x\,dx.$$ The integral on the far right is easy when $n=1$, but if $n\ge 2$ then it's only slightly less problematic than the integral we started with. Still, it's an improvement, so we'll bear it in mind: $$\int x^n\sin x\,dx=-x^n\cos x+n\int x^{n-1}\cos x\,dx\quad\quad\text{for }n\ge 1.\tag{1}$$ Now let's suppose $n\geq 2$, and integrate $\int x^{n-1}\cos x\, dx$ by parts. Take $u_2=x^{n-1}$ and $dv_2=\cos x\,dx$, so $du_2=(n-1)x^{n-2}\, dx$ and $v_2=\sin x$. Then $$\int x^{n-1}\cos x\,dx=\int u_2\,dv_2=u_2v_2-\int v_2\,du_2=x^{n-1}\sin x-(n-1)\int x^{n-2}\sin x\,dx,$$ so by $(1)$, we have \begin{align}\int x^n\sin x\, dx &= -x^n\cos x+n\int x^{n-1}\cos x\,dx\\ &= -x^n\cos x+nx^{n-1}\sin x-n(n-1)\int x^{n-2}\sin x\,dx.\end{align} Hence, we've rewritten the original integral in terms of polynomial combinations of $\sin x$ and $\cos x$, together with an integer multiple of an integral much like the one we started with, but with a power of $x$ that is $2$ smaller. This will allow us to make an inductive argument, but with jumps of $2$, so we'll need $2$ base cases instead of $1$. Namely, we'll need base cases $n=1,2$, and we'll induce along the odd $n$ and the even $n$ separately. Let's bear it in mind: $$\int x^n\sin x\, dx=-x^n\cos x+nx^{n-1}\sin x-n(n-1)\int x^{n-2}\sin x\,dx\quad\text{for }n\ge 2.\tag{2}$$

For the $n=1$ case, we can simply use $(1)$ to get $$\int x\sin x\,dx=-x\cos x+\int\cos x\,dx=-x\cos x+\sin x.$$ On the other hand, the following $4$ lines are all equal:

$$\sum_{k=0}^{\lfloor{1/2}\rfloor}(-1)^{k+1}x^{1-2k}{1!\over(1-2k)!}\cos x+\sum_{k=0}^{\lfloor{(1-1)/2}\rfloor}(-1)^kx^{1-2k-1}{1!\over(1-2k-1)!}\sin x$$

$$\sum_{k=0}^0(-1)^{k+1}x^{1-2k}{1\over(1-2k)!}\cos x+\sum_{k=0}^0(-1)^kx^{-2k}{1\over(-2k)!}\sin x$$

$$(-1)^{0+1}x^{1-0}{1\over(1-0)!}\cos x+(-1)^0x^{0}{1\over(0)!}\sin x$$ $$-x\cos x+\sin x,$$ so we're okay in the first base case.

For the $n=2$ case, we can similarly use $(2)$ and calculate the sums explicitly to confirm that the formula holds.

Now, let's do the odd induction. We're considering all $n=2m-1$ ($m\in\Bbb N$). Let's substitute this into the desired formula to get what we're trying to prove in terms of $m$, instead. Observing that that $\lfloor\frac{n}2\rfloor=\lfloor m-\frac12\rfloor=m-1$ and $\lfloor\frac{n-1}2\rfloor=\lfloor m-1\rfloor=m-1,$ we want to show that \begin{align}\int x^{2m-1}\sin x\,dx=\sum_{k=0}^{m-1}(-1)^{k+1}x^{2m-1-2k}{(2m-1)!\over(2m-1-2k)!}\cos x\\+\sum_{k=0}^{m-1}(-1)^kx^{2m-2-2k}{(2m-1)!\over(2m-2-2k)!}\sin x\end{align}\tag{3} for all $m\in\Bbb N$. We already know the formula holds in the $m=1$ ($n=1$) case, and by $(2)$, we have \begin{align}\int x^{2(m+1)-1}\sin x\, dx=-x^{2(m+1)-1}\cos x+\bigl(2(m+1)-1\bigr)x^{2(m+1)-2}\sin x\\-\bigl(2(m+1)-1\bigr)\bigl(2(m+1)-2\bigr)\int x^{2m-1}\sin x\,dx\end{align}\tag{4} for all $m\geq 1$.

Suppose for some $m$ that $(3)$ holds. Note that for any function $f(x)$, we have $\sum\limits_{k=0}^{m-1}f(k)=\sum\limits_{k=1}^mf(k-1)$. Using this reindexing trick, we have by $(3)$ that \begin{align}\int x^{2m-1}\sin x\,dx &=\sum_{k=0}^{m-1}(-1)^{k+1}x^{2m-1-2k}{(2m-1)!\over(2m-1-2k)!}\cos x\\ &{}\qquad+\sum_{k=0}^{m-1}(-1)^kx^{2m-2-2k}{(2m-1)!\over(2m-2-2k)!}\sin x\\ &=\sum_{k=1}^{m}(-1)^{(k-1)+1}x^{2m-1-2(k-1)}{(2m-1)!\over(2m-1-2(k-1))!}\cos x\\ &{}\qquad+\sum_{k=1}^{m}(-1)^{k-1}x^{2m-2-2(k-1)}{(2m-1)!\over(2m-2-2(k-1))!}\sin x\\ &=(-1)^{-1}\sum_{k=1}^{m}(-1)^{k+1}x^{2m+1-2k}{(2m-1)!\over(2m+1-2k))!}\cos x\\ &{}\qquad+(-1)^{-1}\sum_{k=1}^{m}(-1)^{k}x^{2m-2k}{(2m-1)!\over(2m-2k)!}\sin x\\ &=-\sum_{k=1}^{(m+1)-1}(-1)^{k+1}x^{2(m+1)-1-2k}{(2(m+1)-3)!\over(2(m+1)-1-2k))!}\cos x\\ &{}\qquad-\sum_{k=1}^{(m+1)-1}(-1)^{k}x^{2(m+1)-2k}{(2(m+1)-3)!\over(2(m+1)-2-2k)!}\sin x,\end{align} and so \begin{align}-\bigl(2(m+1)-1\bigr)\bigl(2(m+1)-2\bigr)\int x^{2m-1}\sin x\,dx =\sum_{k=1}^{(m+1)-1}(-1)^{k+1}x^{2(m+1)-1-2k}{(2(m+1)-1)!\over(2(m+1)-1-2k))!}\cos x\\ {}\qquad+\sum_{k=1}^{(m+1)-1}(-1)^{k}x^{2(m+1)-2k}{(2(m+1)-1)!\over(2(m+1)-2-2k)!}\sin x.\end{align} Thus, since $$-x^{2(m+1)-1}\cos x=(-1)^{0+1}x^{2(m+1)-1-0}{(2(m+1)-1)!\over(2(m+1)-1-0)!}\cos x$$ and $$(2(m+1)-1)x^{2(m+1)-2}\sin x=(-1)^{0}x^{2(m+1)-2-0}{(2(m+1)-1)!\over(2(m+1)-2-0)!}\sin x,$$ we have by $(4)$ and the above work that \begin{align}\int x^{2(m+1)-1}\sin x\,dx=\sum_{k=0}^{(m+1)-1}(-1)^{k+1}x^{2(m+1)-1-2k}{(2(m+1)-1)!\over(2(m+1)-1-2k)!}\cos x\\+\sum_{k=0}^{(m+1)-1}(-1)^kx^{2(m+1)-2-2k}{(2(m+1)-1)!\over(2(m+1)-2-2k)!}\sin x,\end{align} and so the desired formula holds in the $m+1$ case, too.

For the even induction, we'll proceed in a similar fashion to the odd induction, except that we'll be considering $n=2m$ for $m\in\Bbb N$.

-
I have no intention of reading this to see whether it's correct, but such effort should not go unrewarded, so, +1 from me. –  Gerry Myerson Nov 6 '12 at 6:20
Thanks very much, Gerry. That almost makes it worth it! ;-) –  Cameron Buie Nov 6 '12 at 6:22
you will get +1 when i have 15 reputation :) –  Gunnar Nov 6 '12 at 11:00

I finally got my proof with differentiation finished, too.

If $$f(x) = \sum_{k=0}^{\lfloor{n/2}\rfloor}(-1)^{k+1}x^{n-2k}{n!\over(n-2k)!}\cos x+\sum_{k=0}^{\lfloor{(n-1)/2}\rfloor}(-1)^kx^{n-2k-1}{n!\over(n-2k-1)!}\sin x$$

with $n\in \Bbb N$.

then \begin{align}f'(x) &= \left(\sum_{k=0}^{\lfloor{n/2}\rfloor}(-1)^{k+1}x^{n-2k-1}{n!\over(n-2k-1)!}-\sum_{k=0}^{\lfloor{(n-1)/2}\rfloor}(-1)^{k+1}x^{n-2k-1}{n!\over(n-2k-1)!}\right)\cos x\\&{}\quad+\left(\sum_{k=0}^{\lfloor{(n-1)/2}\rfloor}(-1)^{k}x^{n-2k-2}{n!\over(n-2k-2)!}-\sum_{k=0}^{\lfloor{n/2}\rfloor}(-1)^{k+1}x^{n-2k}{n!\over(n-2k)!}\right)\sin x\end{align}

\begin{align}&= \left(\sum_{k=0}^{\lfloor{n/2}\rfloor}(-1)^{k+1}x^{n-2k-1}{n!\over(n-2k-1)!}-\sum_{k=0}^{\lfloor{(n-1)/2}\rfloor}(-1)^{k+1}x^{n-2k-1}{n!\over(n-2k-1)!}\right)\cos x\\&{}\quad+\left(\sum_{k=2}^{\lfloor{(n-1)/2}\rfloor+2}(-1)^{k}x^{n-2k+2}{n!\over(n-2k+2)!}-\sum_{k=1}^{\lfloor{n/2}\rfloor+1}(-1)^{k}x^{n-2k+2}{n!\over(n-2k+2)!}\right)\sin x\end{align}

\begin{align}&=\left(\sum_{k=0}^{\lfloor{n/2}\rfloor}(-1)^{k+1}x^{n-2k-1}{n!\over(n-2k-1)!}-\sum_{k=0}^{\lfloor{(n-1)/2}\rfloor}(-1)^{k+1}x^{n-2k-1}{n!\over(n-2k-1)!}\right)\cos x\\ &{}\quad+\left(\sum_{k=2}^{\lfloor{(n-1)/2}\rfloor+2}(-1)^{k}x^{n-2k+2}{n!\over(n-2k+2)!}-\sum_{k=2}^{\lfloor{n/2}\rfloor+1}(-1)^{k}x^{n-2k+2}{n!\over(n-2k+2)!}\right)\sin x\\ &{}\quad+ x^n\sin x\end{align}

Now we have to show that (1) $$\sum_{k=0}^{\lfloor{n/2}\rfloor}(-1)^{k+1}x^{n-2k-1}{n!\over(n-2k-1)!}-\sum_{k=0}^{\lfloor{(n-1)/2}\rfloor}(-1)^{k+1}x^{n-2k-1}{n!\over(n-2k-1)!} = 0$$ and (2) $$\sum_{k=2}^{\lfloor{(n-1)/2}\rfloor+2}(-1)^{k}x^{n-2k+2}{n!\over(n-2k+2)!}-\sum_{k=2}^{\lfloor{n/2}\rfloor+1}(-1)^{k}x^{n-2k+2}{n!\over(n-2k+2)!} = 0$$

For even numbers: $$\lfloor{n/2}\rfloor = n/2$$ $$\lfloor{(n-1)/2}\rfloor = (n-2)/2$$

For odd numbers: $$\lfloor{n/2}\rfloor = (n-1)/2$$ $$\lfloor{(n-1)/2}\rfloor = (n-1)/2$$

Also $n!$ is only defined for $$n\ge 0$$

(1) The odd case is trivial because of $$\lfloor{(n-1)/2}\rfloor = \lfloor{n/2}\rfloor$$

Even: We need $$n -2k -1 \ge 0$$ so $$k \le \lfloor{(n-1)/2}\rfloor = (n-2)/2$$

We get: $$\sum_{k=0}^{(n-2)/2}(-1)^{k+1}x^{n-2k-1}{n!\over(n-2k-1)!}-\sum_{k=0}^{(n-2)/2}(-1)^{k+1}x^{n-2k-1}{n!\over(n-2k-1)!} = 0$$

With the same argumentation you can show (2).

It remains: $$= 0\cos x+0\sin x+ x^n\sin x= x^n\sin x$$

-
Nicely done! Persistence pays off. –  Cameron Buie Nov 6 '12 at 11:04

Integrate by parts twice, and use two inductions (odd and even case). You may be able to unite these if you are skillful.

-
I think I may be a mathochist. I went ahead and typed it all out, like an idiot. I think we probably started working on our answers at almost exactly the same time.... /sigh/ –  Cameron Buie Nov 6 '12 at 4:23