---
title: Contour integrals
heading: Integrating along a path in the complex plane
eyebrow: A12 · Lesson 11 · Contour integrals
xp: 40
---

::: hook
A complex function can be integrated along any path in the plane: walk along the path, multiply the function's value by each small step dz, and add up. These **contour integrals** behave unexpectedly well for analytic functions: the integral around a closed path is usually zero, and when it isn't, it depends only on which singular points the path encloses. That's the engine of the rest of the course, from evaluating hard real integrals in a few lines to inverting Laplace transforms. It starts with one integral: around any circle enclosing the origin, $\oint dz/z = 2\pi j$.
:::

::: play
- The arrows are the field $(u, -v)$ made from $f(z) = 1/z$ (its **Pólya field**); for any f, the work this field does along a path is $\text{Re}\oint f\,dz$, and its flux out across the path is $\text{Im}\oint f\,dz$. The readouts compute both numerically, around the circle.
- With the circle around the origin, the integral is $0 + 2\pi j$: real part 0, imaginary part 6.283. Shrink or grow the circle: the value doesn't change.
- Drag the center until the circle no longer encloses the origin: the integral drops to 0. Only whether the singularity is inside matters.
:::
:::

```sim plot
view: flow
x: x = -3..3
y: y = -2..2
slider: cx = -2.5..2.5 step 0.1 = 0.3
slider: cy = -1.5..1.5 step 0.1 = 0.2
slider: r = 0.3..1.8 step 0.1 = 1
dx: x/(x^2 + y^2 + 1e-9)
dy: y/(x^2 + y^2 + 1e-9)
arrows: scaled
path: cx + r*cos(u), cy + r*sin(u) | over: u = 0..2*pi | work: W | flux: P
dot: 0, 0 | label: singularity of 1/z
readout: Re ∮ dz/z = W
readout: Im ∮ dz/z = P
```

::: predict
## What's $\oint z^2\,dz$ around the unit circle?

- [ ] $2\pi j$
- [x] $0$
- [ ] $\pi$
- [ ] $2\pi$

::: reveal
0: $z^2$ has the antiderivative $z^3/3$, and around a closed path the antiderivative returns to its starting value. Only $z^{-1}$ among the powers lacks a single-valued antiderivative (its antiderivative is the multivalued $\log z$), and that's the one whose closed integral isn't zero.
:::
:::

::: nameit
## The definition

For a path $z(t)$, $a \le t \le b$:

$$\int_C f(z)\,dz = \int_a^b f(z(t))\,z'(t)\,dt$$

It's linear, it changes sign when the path is reversed, and it adds over joined paths.

## When there's an antiderivative

If $F' = f$ on a region containing the path, then

$$\int_C f\,dz = F(z_\text{end}) - F(z_\text{start})$$

whatever the path, and every closed integral is zero. Polynomials, $e^z$, $\sin z$ have antiderivatives everywhere.

## The key integral

Around a circle of any radius centered at a, counterclockwise:

$$\oint (z - a)^n\,dz = \begin{cases} 2\pi j & n = -1 \\ 0 & n \ne -1 \end{cases}$$

## Bounding an integral

If $\lvert f\rvert \le M$ on a path of length L, then $\left\lvert\int_C f\,dz\right\rvert \le ML$. It's how integrals over large arcs are shown to vanish (lesson 17).

## Fields

$\oint f\,dz = \oint(u\,dx - v\,dy) + j\oint(v\,dx + u\,dy)$: the work and the outward flux of the vector field $(u, -v)$. For $1/z$ that field is radial, $\mathbf r/r^2$: no circulation, and a flux of 2π out of any loop around the origin, like the field of a line charge.
:::

::: example
## Integrate $z^2$ from 0 to $1 + j$.

::: solution
1. **Antiderivative.**
   $$F(z) = \frac{z^3}{3}$$
2. **Evaluate at the ends.**
   $$\begin{aligned} F(1 + j) - F(0) &= \frac{(1 + j)^3}{3} \\ &= \frac{-2 + 2j}{3} \end{aligned}$$
   along any path.

**Answer:** $(-2 + 2j)/3$, along any path.
:::
:::

::: example
## Find $\oint \frac{dz}{z - 2}$ around $\lvert z\rvert = 1$ and around $\lvert z\rvert = 3$.

::: solution
1. **Find the singularity.** It's at z = 2.
2. **Around |z| = 1.** The unit circle doesn't enclose it, and $1/(z - 2)$ is analytic inside, so the integral is 0.
3. **Around |z| = 3.** This circle encloses it, and deforming the path to a small circle around 2 gives $2\pi j$.

**Answer:** 0 around $\lvert z\rvert = 1$, and $2\pi j$ around $\lvert z\rvert = 3$.
:::
:::

::: example
## Integrate $\bar z$ from 0 to $1 + j$ along two paths: the straight segment, and along the real axis to 1 and then straight up.

::: solution
1. **Straight segment: parametrize.** $z = (1 + j)t$ with $0 \le t \le 1$, so $\bar z = (1 - j)t$ and $dz = (1 + j)\,dt$.
2. **Straight segment: integrate.**
   $$\begin{aligned} I_1 &= \int_0^1(1 - j)(1 + j)t\,dt \\ &= \int_0^1 2t\,dt \\ &= 1 \end{aligned}$$
3. **Two legs: along the axis.**
   $$\int_0^1 x\,dx = \frac12$$
4. **Two legs: going up.** Here $z = 1 + jy$, $\bar z = 1 - jy$ and $dz = j\,dy$, so
   $$\int_0^1(1 - jy)j\,dy = j + \frac12$$
   The total is $I_2 = 1 + j$.
5. **Compare.** The two answers differ, so the integral of $\bar z$ depends on the path. That's what you expect from a function with no complex derivative; for an analytic integrand both paths would agree.

**Answer:** the straight segment gives 1 and the two legs give $1 + j$, so the integral of $\bar z$ depends on the path.
:::
:::

::: check
given: a = 1 | 2; b = 1 | -1; n = 2 | 3
answer: Re((a + j*b)^(n + 1)/(n + 1))
tolerance: 0.5%

## What's the real part of $\int_0^{z_1} z^{\given{n}}\,dz$ with $z_1 = \given{a} + \given{b}j$, along any path?

::: right
Right. $z_1^{n+1}/(n + 1)$ has real part {answer}.
:::

::: misses
- [Re(n*(a + j*b)^(n - 1))] That's the derivative; the antiderivative is $z^{n+1}/(n + 1)$.
- [any] Not yet. Use the antiderivative $z^{n+1}/(n + 1)$.
:::
:::

::: check
given: c = 0 | 1 | 3; r = 2 | 0.5
answer: 2*pi*step(r - c)
tolerance: 0.001

## What's the imaginary part of $\oint \frac{dz}{z - \given{c}}$ around the circle $\lvert z\rvert = \given{r}$, counterclockwise?

::: right
Right. {answer}: $2\pi$ if the point {c} is inside the circle, 0 if not.
:::

::: misses
- [any] Not yet. Is the singularity inside the path?
:::
:::

::: check
given: R = 1 | 2 | 3
answer: 2*pi*R^2
tolerance: 0.5%

## $\bar z$ isn't analytic. What's the imaginary part of $\oint\bar z\,dz$ around $\lvert z\rvert = \given{R}$? (On the circle, $\bar z = R^2/z$.)

::: right
Right. $\oint R^2/z\,dz = 2\pi jR^2$: imaginary part {answer}. Not zero, because $\bar z$ has no antiderivative.
:::

::: misses
- [any] Not yet. Replace $\bar z$ with $R^2/z$ on the circle.
:::
:::

::: check
given: M = 0.5 | 2 | 10; R = 1 | 3 | 5
answer: M*pi*R
tolerance: 0.5%

## On a half circle of radius {R}, $\lvert f\rvert$ never exceeds {M}. What's the bound on $\lvert\int f\,dz\rvert$ along it?

::: right
Right. $ML = M\pi R$ = {answer}.
:::

::: misses
- [M*2*pi*R] A half circle's length is $\pi R$.
- [any] Not yet. The bound times the path's length.
:::
:::

::: check
given: a = 0.5 | 1 | 2; b = 0 | 1
answer: Re(exp(a + j*b) - 1)
tolerance: 0.5%

## What's the real part of $\int_0^{z_1} e^z\,dz$ with $z_1 = \given{a} + \given{b}j$?

::: right
Right. $e^{z_1} - 1$ has real part {answer}.
:::

::: misses
- [Re(exp(a + j*b))] Subtract the antiderivative's value at the start, $e^0 = 1$.
- [any] Not yet. $e^{z_1} - e^0$.
:::
:::

::: check
kind: choice

## A path goes twice around the origin, counterclockwise. What's $\oint dz/z$ along it?

- [ ] $2\pi j$
- [x] $4\pi j$
- [ ] 0
- [ ] $-2\pi j$

::: misses
- [1] Each turn adds $2\pi j$.
- [3] It does circle the singularity, twice.
- [4] Counterclockwise turns count positive.
:::
:::

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

## Integrate $\bar z$ from 0 to $\given{a} + \given{b}j$.

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

### What is the integral along the straight segment? (It's real.)

::: misses
- [(a^2 - b^2)/2] That's the real part of $\int z\,dz$; with $\bar z$ the factor is $(a - bj)(a + bj)$.
- [any] With $z = (a + bj)t$: $\int_0^1(a^2 + b^2)t\,dt$.
:::
:::

::: part
answer: a*b
tolerance: 0.5%

### What is the imaginary part along the axis to {a} and then straight up?

::: misses
- [0] Path matters here: $\bar z$ isn't analytic.
- [any] The vertical leg gives $\int_0^b(a - jy)j\,dy = jab + \frac{b^2}{2}$.
:::
:::
:::

::: check
kind: derivation
vars: R = 3..10

## Bound $\oint\frac{dz}{z^2 + 4}$ on the circle $\lvert z\rvert = R$.

::: step
answer: 1/(R^2 - 4)

### On the circle, $\lvert z^2 + 4\rvert \ge R^2 - 4$. What is the largest $\lvert f\rvert$ can be?
:::

::: step
answer: 2*pi*R/(R^2 - 4)

### What is the ML bound on the integral?
:::

::: right
Right. The bound shrinks like $2\pi/R$, so on large circles the integral goes to zero. (Its actual value is exactly 0 for every R > 2, since the residues at ±2j cancel.)
:::
:::

::: explain
## Why is $\oint dz/z$ around the origin $2\pi j$, when $\oint z^n\,dz$ is zero for every other integer n?

::: model
For $n \ne -1$, $z^n$ has the single-valued antiderivative $z^{n+1}/(n + 1)$, which returns to its starting value after going around a closed path, so the integral is zero. For $n = -1$ the antiderivative is $\log z$, and going once around the origin increases its imaginary part, the angle, by $2\pi$ without returning, so the integral equals that jump, $2\pi j$. Equivalently, parametrizing the circle as $z = re^{jt}$ gives $dz/z = j\,dt$, which integrates to $2\pi j$ whatever the radius.
:::
:::

::: practice

::: check
given: a = 2 | -1; b = 1 | 2; n = 1 | 2
answer: Re((a + j*b)^(n + 1)/(n + 1))
tolerance: 0.5%

## Re of $\int_0^{\given{a} + \given{b}j} z^{\given{n}}\,dz$?

::: misses
- [any] $z_1^{n+1}/(n+1)$.
:::
:::

::: check
given: c = 0.5 | 4; r = 1 | 5
answer: 2*pi*step(r - c)
tolerance: 0.001

## Im of $\oint dz/(z - \given{c})$ on $\lvert z\rvert = \given{r}$?

::: misses
- [any] $2\pi$ if inside, else 0.
:::
:::

::: check
given: M = 1 | 4; R = 2 | 10
answer: M*pi*R
tolerance: 0.5%

## ML bound on a half circle of radius {R} with $\lvert f\rvert \le \given{M}$?

::: misses
- [any] $M\pi R$.
:::
:::
:::
