---
title: Integration by parts
heading: The product rule, run backwards
eyebrow: A6 · Lesson 1 · Integration by parts
xp: 40
---

::: hook
How much charge does a current pulse $i = I_0\,\frac{t}{\tau}e^{-t/\tau}$ deliver? What's the energy in a decaying oscillation? Integrals of products, a polynomial times an exponential, an exponential times a sine, show up in every transient. Substitution doesn't crack them. Integration by parts does: it trades the integral you have for one that's easier, by running the product rule in reverse.
:::

::: play
- The curve is the pulse $\frac{t}{\tau}e^{-t/\tau}$ with $\tau$ = 1. The shaded area up to $T$ is the charge delivered so far.
- Move $T$ out to large values. What total does the area approach?
- Compare the readout with the formula from integration by parts, $1 - (1 + T)e^{-T}$.
:::
:::

```sim plot
view: graph
x: t = 0..8
y: i = 0..0.45
slider: T = 0.5..8 step 0.1 = 2
plot: t*exp(-t) | label: i = t e⁻ᵗ
plot: t*exp(-t) | fill: 0..T | color: ch2
readout: area so far = 1 - (1 + T)*exp(-T) | digits: 5
```

::: predict
## What is $\displaystyle\int_0^\infty t\,e^{-t}\,dt$?

- [ ] 0
- [x] 1
- [ ] $\infty$
- [ ] $e$

::: reveal
1. By parts with $u = t$ and $dv = e^{-t}dt$: $\int t e^{-t}dt = -te^{-t} + \int e^{-t}dt = -(t + 1)e^{-t}$. From 0 to ∞ that's $0 - (-1) = 1$. A pulse that rises and falls this way delivers exactly $I_0\tau$ of charge, the same as a current $I_0$ held for one time constant.
:::
:::

::: nameit
## The formula

From the product rule, $(uv)' = u'v + uv'$. Integrate both sides and rearrange:

$$\int u\,dv = uv - \int v\,du$$

and for definite integrals, $\int_a^b u\,dv = \big[uv\big]_a^b - \int_a^b v\,du$.

**Choosing $u$.** Pick $u$ to be the factor that gets simpler when differentiated, and $dv$ the factor you can integrate. A common guide, in order of preference for $u$: logarithms, inverse trig, algebraic (powers of $x$), trig, exponentials.

## Patterns

**A power times an exponential or a sine:** $u$ = the power. Each round lowers the power by one. $\int x^2e^x dx$ needs two rounds: $(x^2 - 2x + 2)e^x + C$.

**Logarithms:** $u = \ln x$, $dv = dx$. So $\int \ln x\,dx = x\ln x - x + C$.

**An exponential times a sine (the "boomerang"):** parts twice brings the original integral back, and you solve for it:

$$\int e^{at}\cos bt\,dt = \frac{e^{at}(a\cos bt + b\sin bt)}{a^2 + b^2} + C$$

With complex exponentials (A3, and lesson 43 here) it takes one line: it's the real part of $\int e^{(a + jb)t}dt = \frac{e^{(a + jb)t}}{a + jb}$.

**Tabular shortcut:** for $x^n$ times something you can integrate repeatedly, list derivatives of $x^n$ down one column and integrals of the other down the next, then multiply diagonally with alternating signs.
:::

::: example
## Find $\int x^2 e^x\,dx$.

::: solution
1. **First round of parts.** Take $u = x^2$ and $dv = e^x\,dx$:
   $$\int x^2e^x\,dx = x^2e^x - \int 2xe^x\,dx$$
2. **Second round, on $\int 2xe^x\,dx$.** Take $u = 2x$:
   $$\begin{aligned} \int 2xe^x\,dx &= 2xe^x - \int 2e^x\,dx \\ &= 2xe^x - 2e^x \end{aligned}$$
3. **Put them together.**
   $$\begin{aligned} \int x^2e^x\,dx &= x^2e^x - 2xe^x \\ &\quad + 2e^x + C \\ &= (x^2 - 2x + 2)e^x + C \end{aligned}$$
4. **Check by differentiating.**
   $$\begin{aligned} &(2x - 2)e^x + (x^2 - 2x + 2)e^x \\ &= x^2e^x \end{aligned}$$

**Answer:** $\int x^2e^x\,dx = (x^2 - 2x + 2)e^x + C$.
:::
:::

::: example
## Find $\int_1^e \ln x\,dx$.

::: solution
1. **Choose the parts.** Take $u = \ln x$ and $dv = dx$, so $du = dx/x$ and $v = x$:
   $$\begin{aligned} \int_1^e \ln x\,dx &= \big[x\ln x\big]_1^e \\ &\quad - \int_1^e x \cdot \frac{1}{x}\,dx \end{aligned}$$
2. **Evaluate both parts.**
   $$\begin{aligned} \int_1^e \ln x\,dx &= (e - 0) - (e - 1) \\ &= 1 \end{aligned}$$

**Answer:** $\int_1^e \ln x\,dx = 1$.
:::
:::

::: example
## Find $\int_0^\pi e^x\sin x\,dx$.

::: solution
1. **Integrate by parts twice.** Use the exponential as $dv$ both times, and call the integral $I$:
   $$\begin{aligned} I &= e^x\sin x - \int e^x\cos x\,dx \\ &= e^x\sin x - e^x\cos x - I \end{aligned}$$
2. **Solve for $I$.** The integral comes back on the right, so solve for it:
   $$I = \tfrac12e^x(\sin x - \cos x)$$
3. **Evaluate from 0 to $\pi$.**
   $$\begin{aligned} &\tfrac12\left(e^\pi(0 + 1) - (0 - 1)\right) \\ &= \frac{e^\pi + 1}{2} \\ &= 12.07 \end{aligned}$$

**Answer:** $\int_0^\pi e^x\sin x\,dx = \frac{e^\pi + 1}{2} = 12.07$.
:::
:::

::: check
kind: expression
given: k = 2 | 3 | 5
answer: (x/k - 1/k^2)*exp(k*x)
vars: x = -1..1

## Find $\int x\,e^{\given{k}x}\,dx$ (constant zero).

::: right
Right. $u = x$: $\frac{x}{k}e^{kx} - \int\frac{1}{k}e^{kx}dx = \left(\frac{x}{k} - \frac{1}{k^2}\right)e^{kx}$.
:::

::: misses
- [x*exp(k*x)/k] Subtract the remaining integral, $\frac{1}{k^2}e^{kx}$.
- [(x - 1)*exp(k*x)] That's the answer for $k = 1$. Keep the factors of $1/k$.
- [any] Not yet. Parts with $u = x$, $dv = e^{kx}dx$.
:::
:::

::: check
given: I0 = 1 | 2 | 5; tau = 2 | 10
answer: I0*tau
unit: µC

## A current pulse is $i = \given{I0}\frac{t}{\tau}e^{-t/\tau}$ mA with $\tau$ = {tau} ms. How much charge does it deliver in all, in µC?

::: right
Right. Substituting $u = t/\tau$, it's $I_0\tau\int_0^\infty ue^{-u}du = I_0\tau$ = {answer}.
:::

::: misses
- [I0] Don't forget the factor of $\tau$ from $dt = \tau\,du$.
- [I0*tau/2] $\int_0^\infty ue^{-u}du = 1$, not $\frac{1}{2}$.
- [any] Not yet. Substitute $u = t/\tau$, then parts.
:::
:::

::: check
given: b = 2 | 3 | 5
answer: b*ln(b) - b + 1
tolerance: 0.5%

## Evaluate $\int_1^{\given{b}}\ln x\,dx$.

::: right
Right. $\big[x\ln x - x\big]_1^{\given{b}}$ = {answer}.
:::

::: misses
- [b*ln(b)] Subtract the $\int dx$ term, and the value at 1.
- [any] Not yet. $u = \ln x$, $dv = dx$.
:::
:::

::: check
given: a = 1 | 2; b = 3 | 4
answer: a/(a^2 + b^2)
tolerance: 0.5%

## Evaluate $\displaystyle\int_0^\infty e^{-\given{a}t}\cos(\given{b}t)\,dt$.

::: right
Right. The boomerang formula at the limits gives $\frac{a}{a^2 + b^2}$ = {answer}.
:::

::: misses
- [1/a] That's without the cosine. The oscillation reduces the area.
- [b/(a^2 + b^2)] That's the integral with $\sin bt$.
- [any] Not yet. Parts twice, or use $\frac{e^{-at}(-a\cos bt + b\sin bt)}{a^2 + b^2}$.
:::
:::

::: check
kind: expression
answer: (x^2 - 2*x + 2)*exp(x)
vars: x = -1..2

## Find $\int x^2e^x\,dx$ (constant zero).

::: right
Right. Two rounds of parts: $(x^2 - 2x + 2)e^x$.
:::

::: misses
- [(x^2 - 2*x)*exp(x)] One more term from the last round: $+2e^x$.
- [x^2*exp(x)] That's only $uv$ from the first round. Subtract $\int 2xe^x dx$.
- [any] Not yet. Parts twice, or the tabular method.
:::
:::

::: check
kind: parts
given: k = 1 | 3 | 4; b = 2 | 3

## Integrate by parts.

::: part
answer: 2/k^3
tolerance: 0.5%

### $\displaystyle\int_0^\infty t^2e^{-\given{k}t}\,dt$

::: misses
- [1/k^2] That's $\int te^{-kt}$. With $t^2$, parts is needed twice.
- [any] Twice by parts, or $\int_0^\infty t^ne^{-kt}dt = n!/k^{n+1}$.
:::
:::

::: part
answer: b^2*ln(b)/2 - b^2/4 + 1/4
tolerance: 0.5%

### $\displaystyle\int_1^{\given{b}}x\ln x\,dx$

::: misses
- [any] $u = \ln x$, $dv = x\,dx$: $\frac{x^2}{2}\ln x - \frac{x^2}{4}$.
:::
:::
:::

::: check
kind: derivation
vars: x = 0.5..5

## Integrate $\ln x$ by parts with $u = \ln x$ and $dv = dx$.

::: step
answer: x*ln(x)

### What is $uv$?
:::

::: step
answer: x*ln(x) - x

### $\int v\,du = \int x \cdot \frac1x\,dx$. Finish: what is $\int\ln x\,dx$?
:::

::: right
Right. $\int\ln x\,dx = x\ln x - x + C$: parts works even with an invisible $dv = dx$.
:::
:::

::: explain
## How do you decide which factor to call $u$ in integration by parts?

::: model
Choose $u$ so that differentiating it makes the problem simpler, and choose $dv$ as something you can integrate. A power of $x$ makes a good $u$ because each derivative lowers the power until it disappears, while exponentials and sines are easy to integrate and don't get worse. A logarithm is a good $u$ because its derivative, $1/x$, is simpler than any antiderivative of it. If the new integral is harder than the old one, swap the choice.
:::
:::

::: practice

::: check
kind: expression
given: k = 2..9 int
answer: -x*cos(k*x)/k + sin(k*x)/k^2
vars: x = -2..2

## Find $\int x\sin(\given{k}x)\,dx$ (constant zero).

::: misses
- [-x*cos(k*x)/k] Add the remaining integral, $\frac{1}{k^2}\sin kx$.
- [any] $u = x$, $dv = \sin kx\,dx$.
:::
:::

::: check
given: n = 1..8 int
answer: 1/(n + 1)^2
tolerance: 0.5%

## Evaluate $\int_0^1 x^{\given{n}}\ln(1/x)\,dx$, which equals $-\int_0^1 x^{\given{n}}\ln x\,dx$.

::: misses
- [any] $u = \ln x$, $dv = x^n dx$; the boundary term vanishes.
:::
:::

::: check
given: a = 2 | 4; b = 1 | 3
answer: b/(a^2 + b^2)
tolerance: 0.5%

## Evaluate $\displaystyle\int_0^\infty e^{-\given{a}t}\sin(\given{b}t)\,dt$.

::: misses
- [a/(a^2 + b^2)] That's the cosine version.
- [any] Parts twice.
:::
:::
:::
