How do you find intx^2 e^(1-x)dx using integration by parts?

$\int {x}^{2} {e}^{1 - x} \mathrm{dx}$ The answer is supposedly $- {x}^{2} {e}^{1 - x} - 2 x {e}^{1 - x} - 2 {e}^{1 - x} + C$, but I don't understand how it came to be. Please explain. Thanks in advance!

Apr 21, 2018

$\int {x}^{2} {e}^{1 - x} \mathrm{dx} = - {x}^{2} {e}^{1 - x} - 2 x {e}^{1 - x} - 2 {e}^{1 - x} + C$

Explanation:

We'll make the following selections:

$u = {x}^{2}$

Take its differential:

$\mathrm{du} = 2 x \mathrm{dx}$

$\mathrm{dv} = {e}^{1 - x} \mathrm{dx}$

Take its integral:

$v = \int {e}^{1 - x} \mathrm{dx} = - {e}^{1 - x}$

Apply the integration by parts formula.

$u v - \int v \mathrm{du} = - {x}^{2} {e}^{1 - x} - \int - 2 x {e}^{1 - x} \mathrm{dx}$

The negatives cancel each other out.

$= - {x}^{2} {e}^{1 - x} + \int 2 x {e}^{1 - x} \mathrm{dx}$

For $\int 2 x {e}^{1 - x} \mathrm{dx}$ we're going to have to apply integration by parts again, making the following selections:

$u = 2 x$

$\mathrm{du} = 2 \mathrm{dx}$

$\mathrm{dv} = {e}^{1 - x} \mathrm{dx}$

$v = - {e}^{1 - x}$

$u v - \int v \mathrm{du} = - 2 x {e}^{1 - x} + 2 \int {e}^{1 - x} \mathrm{dx}$

$\int {e}^{1 - x} \mathrm{dx} = - {e}^{1 - x}$, so we get

$\int 2 x {e}^{1 - x} \mathrm{dx} = - 2 x {e}^{1 - x} - 2 {e}^{1 - x}$

Thus, the entire integral becomes

$\int {x}^{2} {e}^{1 - x} \mathrm{dx} = - {x}^{2} {e}^{1 - x} - 2 x {e}^{1 - x} - 2 {e}^{1 - x} + C$, adding in the constant of integration.