---
title: The residue theorem and real integrals
heading: Hard real integrals, done by going around the poles
eyebrow: A12 · Lesson 17 · The residue theorem and real integrals
xp: 40
---

::: hook
Many real integrals that resist every trick of calculus fall in a few lines once they're seen as pieces of a contour integral. Close the real axis with a large semicircle, show that the semicircle's contribution vanishes as it grows, and the real integral equals $2\pi j$ times the sum of the residues inside. Integrals over a full period of sines and cosines become integrals around the unit circle. Engineers use the results constantly: the noise bandwidth of a filter, the response of a resonant system, the inverse Fourier transform of a rational spectrum, are all integrals of exactly this kind.
:::

::: play
- The contour runs along the real axis from −R to R and back over a semicircle, enclosing the pole at $ja$ of $f = 1/(z^2 + a^2)$ (the pole at $-ja$ is outside).
- The residue at $ja$ is $1/(2ja)$, so the whole contour integral is $2\pi j\cdot\frac{1}{2ja} = \pi/a$ for every R larger than a.
- The readouts bound the semicircle's share with the ML inequality: it shrinks like $1/R$. Make R large and the real-axis integral alone carries the whole $\pi/a$.
:::
:::

```sim plot
view: complex
range: 5
slider: a = 0.3..2 step 0.1 = 1
slider: R = 1..4.5 step 0.1 = 3
curve: u | over: u = -R..R | color: ch2
curve: R*exp(j*u) | over: u = 0..pi | color: ch2
dot: j*a | label: ja (inside)
dot: -j*a | label: −ja
readout: 2πj × residue at ja = pi/a
readout: bound on the arc's part, πR/(R² − a²) = pi*R/(R^2 - a^2 + 1e-9)
```

::: predict
## What's $\int_{-\infty}^{\infty}\frac{dx}{1 + x^2}$?

- [ ] 1
- [ ] $\pi/2$
- [x] $\pi$
- [ ] $2\pi$

::: reveal
π: with a = 1, the contour integral is $2\pi j\cdot\frac{1}{2j} = \pi$, and the arc's part vanishes as R → ∞. Real calculus agrees, through $\arctan x$, but the residue method works just as quickly for integrands with no elementary antiderivative.
:::
:::

::: nameit
## The residue theorem

If f is analytic on and inside a closed path C except at isolated singularities $a_k$ inside it:

$$\oint_C f\,dz = 2\pi j\sum_k \text{Res}(f, a_k)$$

## Rational functions on the real line

If $f = P/Q$ with $\deg Q \ge \deg P + 2$ and no poles on the real axis, the semicircle's part vanishes (ML: $\lvert f\rvert$ falls like $1/R^2$ on an arc of length πR), so

$$\int_{-\infty}^{\infty} f(x)\,dx = 2\pi j\sum_{\text{upper half-plane}}\text{Res}(f, a_k)$$

## Integrals over a period

For $\int_0^{2\pi}F(\cos\theta, \sin\theta)\,d\theta$, set $z = e^{j\theta}$: $\cos\theta = \frac{z + 1/z}{2}$, $\sin\theta = \frac{z - 1/z}{2j}$, $d\theta = \frac{dz}{jz}$, and integrate around the unit circle.

## Fourier-type integrals

For $\int f(x)e^{jkx}dx$ with k > 0, close in the upper half-plane, where $e^{jkz}$ decays; **Jordan's lemma** shows the arc vanishes when f merely falls off like 1/R. Real parts give the cosine integrals.
:::

::: example
## Evaluate $\int_0^{2\pi}\frac{d\theta}{a + b\cos\theta}$ for $a > \lvert b\rvert$.

::: solution
1. **Substitute $z = e^{j\theta}$.** The integral becomes
   $$\oint\frac{2\,dz}{j(bz^2 + 2az + b)}$$
2. **Find the pole inside.** The quadratic's roots multiply to 1; the one inside the unit circle is
   $$z_1 = \frac{-a + \sqrt{a^2 - b^2}}{b}$$
3. **Its residue.**
   $$\begin{aligned} \text{Res} &= \frac{2}{j\,b(z_1 - z_2)} \\ &= \frac{2}{j\cdot 2\sqrt{a^2 - b^2}} \end{aligned}$$
4. **Multiply by 2πj.**
   $$I = \frac{2\pi}{\sqrt{a^2 - b^2}}$$

**Answer:** $\frac{2\pi}{\sqrt{a^2 - b^2}}$.
:::
:::

::: example
## Evaluate $\int_{-\infty}^{\infty}\frac{\cos kx}{x^2 + a^2}dx$ for k, a > 0.

::: solution
1. **Use the exponential.** Take $\int\frac{e^{jkx}}{x^2 + a^2}dx$ and close above.
2. **Residue at ja.**
   $$\text{Res} = \frac{e^{-ka}}{2ja}$$
3. **The integral.**
   $$\begin{aligned} \int\frac{e^{jkx}}{x^2 + a^2}dx &= 2\pi j\cdot\frac{e^{-ka}}{2ja} \\ &= \frac{\pi}{a}e^{-ka} \end{aligned}$$
   already real.
4. **Take the real part.** So the cosine integral is $\frac{\pi}{a}e^{-ka}$ (and the sine integral is 0, by symmetry).

**Answer:** $\frac{\pi}{a}e^{-ka}$.
:::
:::

::: example
## Evaluate $\int_{-\infty}^{\infty}\frac{dx}{x^4 + 1}$.

::: solution
1. **Close the contour.** Use a large semicircle in the upper half-plane; on it $\lvert f\rvert \approx 1/R^4$, so the arc contributes nothing as R grows.
2. **Poles inside.** The poles are the fourth roots of −1, and two are inside: $z_1 = e^{j\pi/4}$ and $z_2 = e^{3j\pi/4}$.
3. **Residues.** At a root of $z^4 + 1$, the residue is $\frac{1}{4z_k^3}$, and since $z_k^4 = -1$ this equals $-\frac{z_k}{4}$. The sum is
   $$-\frac{e^{j\pi/4} + e^{3j\pi/4}}{4} = -\frac{j\sqrt2}{4}$$
4. **The integral.**
   $$\begin{aligned} I &= 2\pi j\left(-\frac{j\sqrt2}{4}\right) \\ &= \frac{\pi\sqrt2}{2} \\ &= \frac{\pi}{\sqrt2} \\ &= 2.221 \end{aligned}$$

**Answer:** $\frac{\pi}{\sqrt2} = 2.221$.
:::
:::

::: check
given: a = 0.5 | 2 | 3
answer: pi/a
tolerance: 0.5%

## What's $\int_{-\infty}^{\infty}\frac{dx}{x^2 + \given{a}^2}$?

::: right
Right. $\pi/a$ = {answer}.
:::

::: misses
- [2*pi/a] The residue at $ja$ is $1/(2ja)$, which brings a factor of ½.
- [any] Not yet. $2\pi j\cdot\text{Res}$ at $ja$.
:::
:::

::: check
given: a = 2 | 3 | 5; b = 1 | -1 | 1.5
answer: 2*pi/sqrt(a^2 - b^2)
tolerance: 0.5%

## What's $\int_0^{2\pi}\frac{d\theta}{\given{a} + \given{b}\cos\theta}$?

::: right
Right. $2\pi/\sqrt{a^2 - b^2}$ = {answer}.
:::

::: misses
- [2*pi/a] Not quite: the cosine term changes the value; $\sqrt{a^2 - b^2}$, not a.
- [any] Not yet. $2\pi/\sqrt{a^2 - b^2}$.
:::
:::

::: check
given: k = 0.5 | 1 | 2; a = 1 | 2
answer: pi/a*exp(-k*a)
tolerance: 0.5%

## What's $\int_{-\infty}^{\infty}\frac{\cos(\given{k}x)}{x^2 + \given{a}^2}dx$?

::: right
Right. $\frac{\pi}{a}e^{-ka}$ = {answer}.
:::

::: misses
- [pi/a] The factor $e^{jkz}$ is $e^{-ka}$ at the pole $ja$.
- [any] Not yet. Residue of $e^{jkz}/(z^2 + a^2)$ at $ja$.
:::
:::

::: check
given: a = 0.5 | 1 | 2
answer: pi/(2*a^3)
tolerance: 0.5%

## What's $\int_{-\infty}^{\infty}\frac{dx}{(x^2 + \given{a}^2)^2}$? (The pole at $ja$ is double.)

::: right
Right. $\pi/(2a^3)$ = {answer}.
:::

::: misses
- [pi/a^3] The double-pole residue is $\frac{d}{dz}(z + ja)^{-2}$ at $ja$: $\frac{-2}{(2ja)^3}$.
- [any] Not yet. Use the order-2 residue formula.
:::
:::

::: check
given: R = 2 | 5 | 20; a = 1
answer: pi*R/(R^2 - a^2)
tolerance: 0.5%

## On the semicircle of radius {R}, $\lvert 1/(z^2 + 1)\rvert \le 1/(R^2 - 1)$. What bound does ML give on the arc's integral?

::: right
Right. $\pi R/(R^2 - 1)$ = {answer}, going to 0 as R grows.
:::

::: misses
- [any] Not yet. M = $1/(R^2 - 1)$, L = πR.
:::
:::

::: check
kind: choice

## For $\int_{-\infty}^{\infty}\frac{e^{3jx}}{x^2 + 4}dx$, which half-plane should the contour close in?

- [x] The upper half-plane, where $e^{3jz}$ decays
- [ ] The lower half-plane
- [ ] Either; the answer's the same
- [ ] Neither: the integral doesn't converge

::: misses
- [2] There $e^{3jz}$ grows exponentially, so the arc doesn't vanish.
- [3] Only one of them has an arc that vanishes.
- [4] It converges, to $\frac{\pi}{2}e^{-6}$.
:::
:::

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

## Two Lorentzians, with $0 < \given{a} < \given{b}$.

::: part
answer: pi/(a*b*(a + b))
tolerance: 0.5%

### What is $\int_{-\infty}^{\infty}\frac{dx}{(x^2 + \given{a}^2)(x^2 + \given{b}^2)}$?

::: misses
- [pi/(a*b)] Add the residues at $ja$ and $jb$; they don't simply multiply.
- [any] Partial fractions in $x^2$, or residues at $ja$ and $jb$.
:::
:::

::: part
answer: pi/(a + b)
tolerance: 0.5%

### What is $\int_{-\infty}^{\infty}\frac{x^2\,dx}{(x^2 + \given{a}^2)(x^2 + \given{b}^2)}$?

::: misses
- [pi/(a*b*(a + b))] The $x^2$ on top changes the residues.
- [any] $\frac{x^2}{(x^2 + a^2)(x^2 + b^2)} = \frac{1}{b^2 - a^2}\left(\frac{b^2}{x^2 + b^2} - \frac{a^2}{x^2 + a^2}\right)$.
:::
:::
:::

::: check
kind: derivation
vars: a = 0.5..3, k = 0.5..3

## Evaluate $\int_{-\infty}^{\infty}\frac{x\sin kx}{x^2 + a^2}\,dx$ through $\frac{ze^{jkz}}{z^2 + a^2}$, closing in the upper half-plane.

::: step
answer: exp(-k*a)/2

### What is the residue at $z = ja$?
:::

::: step
answer: pi*exp(-k*a)

### The integral of $\frac{xe^{jkx}}{x^2 + a^2}$ is $2\pi j$ times that. What is the sine integral, its imaginary part?
:::

::: right
Right. $\pi e^{-ka}$. The integrand falls only like $1/x$, so this needs Jordan's lemma for the arc.
:::
:::

::: explain
## Why does the integral over the large semicircle vanish for $\int P/Q$ when Q's degree exceeds P's by at least 2?

::: model
On a semicircle of radius R, the integrand's size behaves like $R^{\deg P - \deg Q}$, at most $C/R^2$ for large R, while the semicircle's length is πR. By the ML inequality its integral is at most $\pi R \cdot C/R^2 = \pi C/R$, which goes to zero as R grows. So in the limit the closed contour integral, fixed at $2\pi j$ times the enclosed residues once R is large enough to enclose all the upper poles, equals the integral along the whole real line.
:::
:::

::: practice

::: check
given: a = 0.5 | 1 | 1.5 | 2 | 3 | 4
answer: pi/a
tolerance: 0.5%

## $\int_{-\infty}^{\infty}dx/(x^2 + \given{a}^2)$?

::: misses
- [any] $\pi/a$.
:::
:::

::: check
given: a = 3 | 4; b = 2 | -2
answer: 2*pi/sqrt(a^2 - b^2)
tolerance: 0.5%

## $\int_0^{2\pi}d\theta/(\given{a} + \given{b}\cos\theta)$?

::: misses
- [any] $2\pi/\sqrt{a^2 - b^2}$.
:::
:::

::: check
given: k = 1 | 3; a = 0.5 | 1
answer: pi/a*exp(-k*a)
tolerance: 0.5%

## $\int\cos(\given{k}x)/(x^2 + \given{a}^2)\,dx$?

::: misses
- [any] $\frac{\pi}{a}e^{-ka}$.
:::
:::
:::
