We already know how to differentiate the product of two functions (see Section 15.3.3: Product & Quotient Rules), but what about integrating them?
Suppose we want to find $\int x \cos x \dif x$, so we’re looking to find a function that has the derivative $x\cos x$. Any ideas?
Our first thought might be ‘$\frac{\dif}{\dif x} \sin x = \cos x$ so maybe something like $x\sin x$ might work.’ See if that works, and if it doesn’t then modify it so that it does. Show assumed knowledge
When we differentiate $x\sin x$ we get $1\sin x + x\cos x$ using the product rule. The $x\cos x$ that we wanted is in there, but there’s also a pesky $\sin x$. How can we get rid of that?
Instead of using $x\sin x$, what we need is $x\sin x + \text{something}$, where the ‘something’ is going to cancel out with the extra $\sin x$ after we differentiate, so the derivative of the something needs to be $-\sin x$. What we need is $\cos x$.
Let’s check that it works: \begin{align*} \frac{\dif}{\dif x} \left(x\sin x + \cos x\right) &= 1\sin x + x\cos x - \sin x\\ &= x\cos x. \end{align*} It works! Hence $\int x\cos x\dif x = x\sin x + \cos x + c$.
What about a definite integral? Find $\int_0^{\pi/2} x\cos x\dif x$ Show answer
\begin{align*} \int_0^{\pi/2} x\cos x\dif x &= \left[ x\sin x + \cos x\right]_0^{\pi/2}\\ &= \left(\frac{\pi}{2}\times1 + 0\right) - \left(0 + 1\right)\\ &= \frac{\pi}{2} - 1 \end{align*}
What we just did is called integration by parts, which is commonly used to integrate the product of two functions. Let’s work on a general formula which we can apply to any two functions.
You can apply any operation to both sides of an equation as long as you do the same thing to each side; this works for integration as well as differentiation. By integrating both sides of the product rule, show that \[\int f’(x)g(x) \dif x = f(x)g(x) - \int f(x) g’(x) \dif x.\] Show answer
\begin{align*} \frac{\dif }{\dif x}\left(f(x)g(x)\right) &= f’(x)g(x) + f(x)g’(x)\\ \int\frac{\dif }{\dif x}\left(f(x)g(x)\right)\dif x &= \int \left(f’(x)g(x) + f(x)g’(x)\right)\dif x\\ f(x)g(x) + c &= \int f’(x)g(x) \dif x + \int f(x)g’(x)\dif x\\ \int f’(x)g(x) \dif x &= f(x)g(x) + c - \int f(x)g’(x)\dif x \end{align*} When we integrate $f(x)g’(x)$ we’ll also get a constant, so the $+c$ after $f(x)g(x)$ is unnecessary, and we can drop it.
A slightly different way to derive this formula would be to re-arrange the product rule first to get $f’(x)g(x) = \frac{\dif }{\dif x}\left(f(x)g(x)\right) - f(x)g’(x)$ and then integrate.
Whenever we use integration by parts there is a choice of which function to regard as $f’(x)$ and which as $g(x)$. When we integrated $x\cos x$ above, we used $f’(x) = \cos x$ and $g(x) = x$ which was a good choice because that makes $f(x)g’(x) = \sin x$ which is easily integrable. If we had done it the other way and made $f’(x) = x$ and $g(x) = \cos x$ then $f(x)g’(x) = -\frac{1}{2}x^2 \sin x$ which is much harder to integrate. You must make the choice so that $f(x)g’(x)$ is easily integrable.
When I use integration by parts, I think of it as ‘integrate one function, then differentiate the other’ (integrate $f’(x)$ to get $f(x)$ then differentiate $g(x)$ to get $g’(x)$). For example, with $x\cos x$ you integrate the $\cos x$ part, leaving the $x$ part unchanged, to get $x \sin x$, then you write ‘$-\int$’, then you differentiate the $x$ part, leaving the $\sin x$ unchanged, to get $f(x)g’(x) = 1\sin x$. Putting it all together gives \[\int x\cos x \dif x = x\sin x - \int 1\sin x \dif x.\] If you can ‘integrate one function, then differentiate the other’ in your head then you can check if the result is easily integrable to see if you made the right choice before you write anything down.
Now let’s try applying the formula we derived to find $\int x\ln x \dif x$. Show answer
If we choose $\ln x$ as the part to integrate we quickly run into trouble, because at this stage we don’t know how to integrate $\ln x$ (see Question 15.4.23 for that). So we must integrate the $x$ part, and differentiate the $\ln x$ part: \begin{align*} \int x\ln x\dif x &= \frac{x^2}{2} \ln x - \int \frac{x^2}{2} \frac{1}{x} \dif x\\ &= \frac{x^2}{2} \ln x - \int \frac{x}{2} \dif x\\ &= \frac{x^2}{2} \ln x - \frac{x^2}{4} + c \end{align*}
When doing a definite integral, you can just sub the limits in as usual after finding the indefinite integral, like so: \[\int_a^b f’(x)g(x) \dif x = \left[ f(x)g(x) - \int f(x)g’(x)\dif x \right]_a^b\] or what’s usually more convenient is to apply the limits separately to the two parts: \[\int_a^b f’(x)g(x) \dif x = \left. f(x)g(x) \right|_a^b - \int_a^b f(x)g’(x)\dif x\]
Find $\int_0^2 x e^x \dif x$. Show answer
Choosing to integrate the $e^x$ part and differentiate the $x$ part gives $1e^x$ which we can integrate easily, whereas the other choice gives $f(x)g’(x) = \frac{1}{2}x^2 e^x$ which is even worse than the original function. \begin{align*} \int_0^2 x e^x \dif x &= \left.x e^x\right|_0^2 - \int_0^2 1 e^x \dif x\\ &= 2e^2 - 0e^0 - \left[ e^x \right]_0^2\\ &= 2e^2 - \left[e^2 - e^0\right]\\ &= e^2 + 1. \end{align*}
Remember:
The formula for integration by parts, with indefinite integrals:
\[\int f’(x)g(x)\dif x=f(x)g(x) - \int f(x)g’(x)\dif x\]
And with definite integrals: \[\int_a^b f’(x)g(x)\dif x=\left.f(x)g(x)\right|_a^b - \int_a^bf(x)g’(x)\dif x\] Show practice questions
Now for some applications of integration by parts which will require some ingenuity.
Find $\int\ln x\dif x$. Show hint
\begin{align*} \int\ln x\dif x &= \int1\times\ln x\dif x\\ &= x\ln x - \int x\times \frac{1}{x}\dif x\\ &= x\ln x - \int 1\dif x\\ &= x\ln x - x + c \end{align*} To check that this is correct, you can differentiate it: \begin{align*} \frac{\dif }{\dif x} (x\ln x - x + c) &= \left(1\ln x + x\frac{1}{x}\right) - 1 + 0\\ &=\ln x \end{align*}
Find $\int x^2\cos x\dif x$. Show hint
We’ll have to use integration by parts twice: \begin{align*} \int x^2\cos x\dif x &= x^2\sin x - \int 2x\sin x\dif x\\ &= x^2\sin x - \left(2x(-\cos x) - \int 2(-\cos x)\dif x \right)\\ &= x^2\sin x + 2x\cos x - 2\sin x + c \end{align*} You can check your answer by differentiating it: \begin{align*} \frac{\dif }{\dif x} \left(x^2\sin x + 2x\cos x - 2\sin x + c\right)&= \left(2x\sin x + x^2\cos x\right) + \left(2\cos x - 2x\sin x\right) - 2\cos x + 0\\ &=x^2\cos x \end{align*}
Find $\int\e^{x}\cos x\dif x$. Show hint
There are a few ways to do this one. We can choose $e^x$ as the function to integrate: \begin{align*} \int\e^{x}\cos x\dif x &= e^x\cos x - \int e^x(-\sin x)\dif x\\ &= e^x\cos x + \int e^x\sin x\dif x\\ &= e^x\cos x + e^x\sin x - \int e^x \cos x \dif x \end{align*} We end up with $\int e^x \cos x \dif x$ again, but that’s ok because we can just solve for it: \begin{align*} 2\int e^x \cos x \dif x &= e^x\cos x + e^x\sin x\\ \int e^x \cos x \dif x &= \frac{e^x\cos x + e^x\sin x}{2} + c \end{align*} (We need to add in the $c$ at the end because of the $c$ we got rid of when we were simplifying the formula for integration by parts in Question 15.4.20.) If it makes things clearer for you, you can give the integral a variable, e.g. let $I = \int e^x \cos x \dif x$, then \begin{align*} I &= e^x\cos x + e^x\sin x - I\\ 2I &= e^x\cos x + e^x\sin x\\ I &= \frac{e^x\cos x + e^x\sin x}{2} \end{align*}
We could instead choose $\cos x$ as the function to integrate: \begin{align*} \int\e^{x}\cos x\dif x &= e^x \sin x - \int e^x \sin x\dif x\\ &= e^x\sin x - \left(e^x(-\cos x) - \int e^x(-\cos x)\dif x\right)\\ &= e^x\sin x + e^x\cos x - \int\e^{x}\cos x\dif x \end{align*} and proceed as before.
A third way to solve this would be to do the integration once each way: \begin{align*} \int\e^{x}\cos x\dif x &= e^x\cos x - \int e^x(-\sin x)\dif x \\ &= e^x\cos x + \int e^x\sin x\dif x \tag{$1$}\\ \int\e^{x}\cos x\dif x &= e^x \sin x - \int e^x \sin x\dif x \tag{$2$} \end{align*} and then solve these two equations simultaneously: \begin{align*} (1) + (2):&&2\int\e^{x}\cos x\dif x &= e^x\cos x + e^x \sin x \end{align*} and so on as before.
Find $\int \e^{\sqrt{x}}\dif x$. Show hint
When we have a complicated function like $\e^{\sqrt{x}}$ then it’s usually best to do a substitution, so let $u = \sqrt{x}$, then \begin{align*} \frac{\dif u}{\dif x} &= \frac{1}{2\sqrt{x}}\\ \dif x &= 2\sqrt{x}\dif u\\ &= 2u \dif u \end{align*} \begin{align*} \int \e^{\sqrt{x}}\dif x &= \int \e^u 2u\dif u \end{align*} Now we can apply integration by parts, integrating $\e^u$ and differentiating $2u$. (Or you might decide to bring the $2$ out the front of the integral first.) \begin{align*} \int \e^{\sqrt{x}}\dif x &= \e^u 2u - \int 2\e^u \dif u\\ &= 2u\e^u - 2\e^u + c\\ &= 2\e^u(u - 1) + c\\ &= 2\e^{\sqrt{x}}(\sqrt{x} - 1) + c \end{align*}