## Integration by parts twice

[11 Nov 2010]

When we first learn how to integrate, the examples we see involve simple polynomials, or single functions like these:

$\int{(x^2+4)}\,dx=\frac{x^3}{3}+4x+C$

$\int{\sin{x}}\,dx=-\cos{x}+C$

### Integrals of products

What if we need to find the integral of a product of 2 functions, like the following example?

Example 1

$\int{{x}\,\sin{x}}\,dx$

This is where we need the important and useful technique in calculus known as integration by parts. (You can see a full explanation starting from basic principles and with more examples here: Integration by parts).

To find this integral, we choose "u" such that its derivative is simpler than u. In this case, we will choose u = x and proceed as follows:

 u = x dv = sin x dx du = dx v = −cos x

We apply the integration by parts formula and find the integral:

$\int{u\hspace{2}dv}=uv-\int{v\hspace{2}du}$

$\int{{x}\,\sin{x}}\,dx=(x)(-\cos{x})-\int{-\cos{x}\,dx$

Tidying this up gives:

$\int{{x}\,\sin{x}}\,dx=-x\,\cos{x}+\int{\cos{x}\,dx$

Now, that last integral is easy and we can write our final answer:

$\int{{x}\,\sin{x}}\,dx=-x\,\cos{x}+\sin{x}+C$

Note 1: The constant of integration (C) appears after we do the final integration.

Note 2: Choosing u and dv can cause some stress, but if you follow the LIATE rule, it is easier. For u, choose whatever comes highest in the follwing list, and choose dv as the lowest in this list.

L – logarithm functions
I – Inverse trigonometric functions
A – Algebraic functions (simple polynomial terms)
T – trigonometric functions
E – Exponential functions

### Integration by parts – twice

Now, let’s see a case that is double-barreled. That is, we don’t get the answer with one round of integration by parts, rather we need to perform integration by parts two times.

Example 2:

$\int{x^2e^x}dx$

In this example we choose u = x2, since this will reduce to a simpler expression on differentiation (and it is higher on the LIATE list), where ex will not.

 u = x2 dv = exdx du = 2x dx v = ex

Now for integration by parts:

$\int{u\hspace{2}dv}=uv-\int{v\hspace{2}du}$

$\int{x^2e^x}dx={x^2}e^x-\int{e^x}(2x)\,dx$

We re-arrange this to give the following, which I call equation [1]:

$\int{x^2e^x}dx={x^2}e^x-2\int{x}\,{e^x}\,dx\;\;\;[1]$

This time we can’t immediately do that final integral, so we need to perform integration by parts again. Choosing "u" so that its derivative is simpler than u again, we have:

 u = x dv = ex dx du = dx v = ex

Note that the u and v here have different values from the u and v at the beginning of Example 2. This can be a trap if you don’t write things carefully!

Now we proceed using integration by parts on $\int{{x}\,e^x}dx$:

$\int{u\hspace{2}dv}=uv-\int{v\hspace{2}du}$

$\int{{x}\,e^x}dx={x}\,e^x-\int{e^x}dx$

That last integral is simple, and we get the following, which I call equation [2]:

$\int{{x}\,e^x}dx={x}\,e^x-e^x+C_1\;\;\;[2]$

But we haven’t finished the question – we must remember we are finding this integral:

$\int{x^2e^x}dx$

This was our answer to the first integration by parts:

$\int{x^2e^x}dx={x^2}e^x-2\int{x}\,{e^x}\,dx\;\;\;[1]$

Substituting answer [2] this into equation gives us:

$\int{x^2e^x}dx={x^2}e^x-2(x\,e^x-e^x)+C$

Tidying this up, we obtain the final answer:

$\int{x^2e^x}dx=e^x(x^2-2x+2)+C$

Notice the place where the constant "+C" appears in our answer – it’s after thel integration has been performed. (Some students get hung up on this step, or add the "+C" before it is appropriate, and some forget to add it at all!) I have used a subscript 1 on the first constant since it is not the same value as the final C.

### Integration by parts twice – with solving

We also come across integration by parts where we actually have to solve for the integral we are finding. Here’s an example.

Example 3:

$\int{e^x\sin{x}\hspace{2}dx$

In this example, it is not so clear what we should choose for "u", since differentiating ex does not give us a simpler expression, and neither does differentiating sin x. We choose the "simplest" possiblity, as follows (even though ex is below trigonometric functions in the LIATE table):

 u = ex dv = sin x dx du = ex dx v = −cos x

Apply the integration by parts formula:

$\int{u\hspace{2}dv}=uv-\int{v\hspace{2}du}$

We obtain the following, which I’ll call equation [3]:

$\int{e^x\sin{x}\hspace{2}}dx=-e^x\cos{x}+\int{e^x\cos{x}\hspace{2}}dx\;\;\;[3]$

Now, for that final integral:

$\int{e^x\cos{x}\hspace{2}}dx$

Once again, we need to decide which function to use for u, and settle on the one which gives simplest derivative:

 u = ex dv = cos x dx du = ex dx v = sin x

Applying integration by parts for the second time:

$\int{u\hspace{2}dv}=uv-\int{v\hspace{2}du}$

We obtain equation [4]:

$\int{e^x\cos{x}\hspace{2}}dx=e^x\sin{x}-\int{e^x\sin{x}\hspace{2}}dx\;\;\;[4]$

Wait a minute – we have a final integral that is the same as what we started with! If we kept going, we would go around in circles and never finish.

Sowe need to perform the following "trick". We substitute our answer for the second integration by parts (equation [4]) into our first integration by parts answer (equation [3].

$\int{e^x\sin{x}\hspace{2}dx$

$=-e^x\cos{x}+\int{e^x\cos{x}\hspace{2}}dx$

$=-e^x\cos{x}+\left[e^x\sin{x}-\int{e^x\sin{x}\hspace{2}}dx\right]$

Removing the brackets:

$\int{e^x\sin{x}\hspace{2}dx=-e^x\cos{x}+e^x\sin{x}-\int{e^x\sin{x}\hspace{2}}{dx}\;\;\;[5]$

Now, this equation is in the following form:

p = -q + r – p

To solve this for p, we just add p to both sides:

2p = -q + r

Then divide both sides by 2:

p = (-q + r)/2

So we will do the same to our integral equation, number [5].

I add $\int{e^x\cos{x}\hspace{2}}dx$ to both sides:

$2\int{e^x\sin{x}\hspace{2}dx=-e^x\cos{x}+e^x\sin{x}+K$

Dividing both sides by 2 gives:

$\int{e^x\sin{x}\hspace{2}dx=\frac{e^x(\sin{x}-\cos{x})}{2}+C$

So we have solved equation [5] for $\int{e^x\sin{x}\hspace{2}dx$, giving us the desired result.

(Note I used a "+K" for the first constant that appeared. My final "C" has value K/2, but normally we only need to be concerned with the final constant.)

### 14 Comments on “Integration by parts twice”

1. Pseudonym says:

I’ve done a lot of integrals by hand in my time, but I don’t think I’ve used integration by parts even once the last 15 years. Let me explain why.

Integration by parts is essentially the product rule for differentiation inverted:

d(uv)/dx = du/dx v + u dv/dx
⇔ ∫ d(uv)/dx dx = ∫ du/dx v dx + ∫ u dv/dx dx
⇔ uv = ∫ du/dx v dx + ∫ u dv/dx dx
⇔ ∫ du/dx v dx = uv – ∫ u dv/dx dx

The problem with applying integration by parts is that it’s often not obvious what to choose for u and v, and even when it is, there are usually constant factors and exact forms which are tricky to get “right”.

Instead, I use the Risch method: Determine a generic product form for the integrand, then differentiate.

Let me explain what I mean.

Consider:

∫ (x² + 3x + 21)e^x dx

What we have is a polynomial in x multiplied by e^x. Now what would happen if we differentiated that?

d/dx [p(x) e^x]
= p’(x) e^x + p(x) e^x
= (p’(x) + p(x)) e^x

Now isn’t that interesting? If p(x) has degree k, then the derivative of p(x) e^x is another polynomial, also of degree k, multiplied by e^x.

So this should also be true if we integrate! That is, there should be some polynomial p(x) such that:

∫ (x² + 3x + 21)e^x dx = p(x) e^x + C

So let’s let p(x) be a generic quadratic polynomial:

p(x) = a2 x² + a1 x + a0

Then:

∫ (x² + 3x + 21)e^x dx = (a2 x² + a1 x + a0) e^x + C

Differentiate both sides, noting that dC/dx = 0.

(x² + 3x + 21)e^x = (a2 x² + a1 x + a0) e^x + (2a2 x + a1) e^x
⇔ x² + 3x + 21 = a2 x² + (a1 + 2a2) x + (a0 + a1)

Matching up coefficients of x gives:

a2 = 1
a1 + 2a2 = 3
a0 + a1 = 21

This is a system of linear equations, three equations in three unknowns. The solution is:

a2 = 1
a1 = 1
a0 = 20

That is:

∫ (x² + 3x + 21)e^x dx = (x² + x + 20) e^x + C

And that’s it. We didn’t have to “do” integration by parts once.

Of course, we could now fake it if we wanted to. In integration, knowing the answer is most of the battle; once you have the right answer, you insert whatever valid reasoning you want to justify it. So if the question asked for integration by parts, you could do that now, and you’d be more likely to get the right answer.

The difficult bit about this method is recognising what “most general form” for the integrand is appropriate. There is a more-or-less systematic way to do this, and most computer algebra systems implement exactly this method. But it requires a little bit of knowledge sometimes.

For example, this integral:

∫ e^x sin x dx

requires noticing that for some constants α, β, γ and δ:

d/dx [e^x (α sin x + β cos x)]
= e^x (γ sin x + δ cos x)

That is, you have to include sin and cos, even though cos doesn’t appear in the integral that you have to perform. But the good news is that the method detects its own errors. If your form wasn’t general enough, you’ll just get a system of equations with no solutions.

2. Murray says:

Thanks for the method, Pseudonym! There is certainly more than one way to skin a cat. Some readers will balk at the simultaneous equations step in the middle, but it is not difficult.

More fundamentally, though, I suspect less and less people are doing any integrations by hand. There are so many good tools out there now, including Wolfram|Alpha.

Is integration by hand going the way of the dinosaur?

3. Dalcde says:

Anyone doing calculus should not have problems with simultaneous equation.

4. Murray says:

@Dalcde: You are right with the word “should”, but the reality is usually something else…

5. sam says:

6. april says:

@murray: yes, u are right. there are lots of devices that do integrations..and actually my calculator has a integration. so, i do use this to check if my calculations are right..
but in our calculus, we always do integration at hand and such devices are just use for checking…

@Dalcde: murray is right.. we do study calculus, but we still have a hard time of doing integrations especially the complex ones.

7. Mridul Gupta says:

I do not agree with you guys at all

Earlier i depended on wolfram for checking/confirming my indefinite integration problems….but since that time i have realized that it just provides integration of very simple functions. Let me give you guys a good example which wolfram cant even calculate in its dreams, but you guys can do it by hand very easily

it is integration of 1 / [sin^5(x)+ cos^5(x)]

I can give many such examples(or you can take it as good questions for practice) which wolfram can never calculate.

Speaking truth, i love doing indefinite integration because it requires an attempt from my side and not just a machine

No grudges against anyone, just putting forward my view. I apologize if it hurts someone.

8. Murray says:

No one is hurt! Certainly there are some integrals that are better done by hand than by machine, since the latter can give us the answer in a pretty messy form.

But I’m not sure why you say Wolfram|Alpha cannot do the integral you mentioned. Here is its solution.

9. Pseudonym says:

I think Mridal Gupta’s point is that Mathematica’s solution is a lot less helpful than any answer you’d get by hand.

But as a general comment: If you want to check your answer, don’t ask Mathematica or Alpha, just differentiate! Differentiation is easy.

Incidentally, I agree with Dalcde. A simple linear system like this should not be difficult for someone doing integral calculus. If it is, then this is a bad comment on the education system.

But then, I never learned trig identities before doing calculus, either. I’ve still only memorised two of them. If I need any others, I derive them.

10. Mridul Gupta says:

Yeah, the complexities of the solution given by wolfram can scare anyone (at least i got scared when I saw that)

and pardon Pseudonym its ‘Mridul’ not ‘Mridal’

11. Thank you says:

wow!!! this helps me out A LOT!!! thank you very much!!!! i’m so happy now

12. nasiriyan says:

thank you so much
this helps me out a lot.

13. JD says:

In simplifying from this step:

\int{x^2e^x}dx={x^2}e^x-2(x\,e^x-e^x)+C

It seems like you forgot to foil in the -2 to everything within the parenthesis, because you report your next answer as

\int{x^2e^x}dx=e^x(x^2-2x-1)+C

In actuality the last part should be = e^x(x^2-2x+2) +C

14. Murray says:

@JD – Thanks for pointing that out. It’s fixed now.

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>