# Recursive formula for the integral

Derive a recursive formula for the integral $$\int_0^\frac{\pi}{2} x^{2}\cos x$$ I tried to do it by parts but when I do it second time there is $x^{n-2}$ I need some help... Is it a good way to solve a problem?

Two integrations by parts will do it.

Let $u=x^2$ and $dv=\cos x\,dx$. (Note, by the way, that you’re missing that $dx$.) Then $du=2x\,dx$, and $v=\sin x$, so

$$\int_0^{\pi/2}x^2\cos x\,dx=\left[x^2\sin x\right]_0^{\pi/2}-2\int_0^{\pi/2}x\sin x\,dx\;.$$

Now let $u=x$ and $dv=\sin x\,dx$, so that $du=dx$ and $v=-\cos x$. Then

$$\int_0^{\pi/2}x\sin x\,dx=\left[-x\cos x\right]_0^{\pi/2}+\int_0^{\pi/2}\cos x\,dx\;.$$

Now just put the pieces together: $\left[x^2\sin x\right]_0^{\pi/2}=\frac{\pi^2}4$, $\left[-x\cos x\right]_0^{\pi/2}=0$, and

$$\int_0^{\pi/2}x^2\cos x\,dx=\frac{\pi^2}4-2\int_0^{\pi/2}\cos x\,dx\;,$$

which is straightforward.

Added: If the problem was really to find a recursive expression for $\int_0^{\pi/2}x^n\cos x\,dx$, we can do that the same way. First let $u=x^n$ and $dv=\cos x\,dx$, so that $du=nx^{n-1}\,dx$, and $v=\sin x$. Then

\begin{align*} \int_0^{\pi/2}x^n\cos x\,dx&=\left[x^n\sin x\right]_0^{\pi/2}-n\int_0^{\pi/2}x^{n-1}\sin x\,dx\\ &=\left(\frac{\pi}2\right)^n-n\int_0^{\pi/2}x^{n-1}\sin x\,dx\;. \end{align*}

Now let $u=x^{n-1}$ and $dv=\sin x\,dx$, so that $du=(n-1)x^{n-2}\,dx$ and $v=-\cos x$. Then

\begin{align*} \int_0^{\pi/2}x^{n-1}\sin x\,dx&=\left[-x^{n-1}\cos x\right]_0^{\pi/2}+(n-1)\int_0^{\pi/2}x^{n-2}\cos x\,dx\\ &=(n-1)\int_0^{\pi/2}x^{n-2}\cos x\,dx\;, \end{align*}

and

\begin{align*} \int_0^{\pi/2}x^n\cos x\,dx&=\left(\frac{\pi}2\right)^n-n\int_0^{\pi/2}x^{n-1}\sin x\,dx\\ &=\left(\frac{\pi}2\right)^n-n(n-1)\int_0^{\pi/2}x^{n-2}\cos x\,dx\;. \end{align*}

This is recursive formula valid for all $n\ge 2$. By using it repeatedly, you can reduce any integral of the form

$$\int_0^{\pi/2}x^n\cos x\,dx$$

to a number plus a multiple of $$\int_0^{\pi/2}\cos x\,dx\;,$$ if $n$ is even, or to a number plus a multiple of $$\int_0^{\pi/2}x\cos x\,dx$$ if $n$ is odd. The first of these integrals is easy, and the second requires only one straightforward integration by parts. The point is that you can use the recursive formula without actually doing the two integrations by parts that produced it. For instance,

\begin{align*} \int_0^{\pi/2}x^8\cos x\,dx&=\left(\frac{\pi}2\right)^8-8\cdot7\int_0^{\pi/2}x^6\cos x\,dx\\ &=\left(\frac{\pi}2\right)^8-56\left(\left(\frac{\pi}2\right)^6-6\cdot 5\int_0^{\pi/2}x^4\cos x\,dx\right)\\ &=\left(\frac{\pi}2\right)^8-56\left(\frac{\pi}2\right)^6+56\cdot30\left(\left(\frac{\pi}2\right)^4-\int_0^{\pi/2}x^2\cos x\,dx\right)\\ &=\left(\frac{\pi}2\right)^8-56\left(\frac{\pi}2\right)^6+1680\left(\frac{\pi}2\right)^4-1680\int_0^{\pi/2}x^2\cos x\,dx\;, \end{align*}

and one more application of the recursive formula leaves you with a with a constant plus $\int_0^{\pi/2}\cos x\,dx$; the only actual integration is at that last step.

• Thank u, I get it, but is it an answer? It doesn't look like a recursive formula. (sorry for missing dx) – keri Aug 29 '13 at 0:48
• @keri: It’s not a recursive formula, because that integral doesn’t require one. Are you sure that the problem wasn’t to find a recursive formula for $$\int_0^{\pi/2}x^n\cos x\,dx\;?$$ – Brian M. Scott Aug 29 '13 at 0:49
• Yes! It's exactly like you wrote. Sorry. My fault. And here is my prob. – keri Aug 29 '13 at 0:56
• @keri: I thought that it might be; I’m adjusting my answer right now. – Brian M. Scott Aug 29 '13 at 0:57
• @keri: I’ve expanded the answer now to include the real problem. Notice that you really do get an $x^{n-2}$ in the result, so you may not have been doing anything wrong except misunderstanding what you were looking for. To cover that possibility, I’ve added an example of how the recursive formula would be used to reduce the number of actual integrations. – Brian M. Scott Aug 29 '13 at 1:13