Complex Analysis Explorer
Every pixel represents a complex number $z$. The color encodes $f(z)$: hue shows the argument (angle), brightness shows the magnitude. Drag the contour across poles and watch the integral jump by exactly $2\pi i$ times the enclosed residues.
What is Domain Coloring?
A complex function $f(z)$ maps one complex number to another. We can't easily plot this—it would require four dimensions. Domain coloring sidesteps the problem: for each input $z$, we compute $f(z)$ and encode the result as a color. The hue represents the argument (angle) of $f(z)$, cycling through the full color wheel. The brightness represents the magnitude $|f(z)|$, with logarithmic scaling so that both very large and very small values are visible.
Poles show up as points where all colors converge and brightness spikes. Zeros are dark points where all colors converge. Branch cuts appear as sharp hue discontinuities.
Contour Integration
A contour integral $\oint f(z)\,dz$ integrates a complex function along a closed curve in the complex plane. We parameterize the contour as $\gamma(t) = c + re^{it}$ for $t \in [0, 2\pi]$, so the integral becomes:
$$\oint f(z)\,dz = \int_0^{2\pi} f(\gamma(t)) \cdot \gamma'(t)\,dt$$The demo computes this numerically using the trapezoidal rule with 500 sample points.
Cauchy’s Integral Theorem
If $f$ is analytic (complex-differentiable) everywhere inside and on the contour, the integral is exactly zero. This is Cauchy's integral theorem. Try it with $f(z) = z^2$ or $f(z) = e^z$—no matter where you place the contour, the integral stays at zero.
The Residue Theorem
When $f$ has isolated singularities (poles) inside the contour, the integral is determined entirely by the residues at those poles:
$$\oint f(z)\,dz = 2\pi i \sum \operatorname{Res}(f, z_k)$$where the sum is over all poles $z_k$ enclosed by the contour. This is one of the most powerful results in mathematics—a complicated integral reduces to a finite sum.
Computing Residues
For a simple pole at $z_0$, the residue is:
$$\operatorname{Res}(f, z_0) = \lim_{z \to z_0} (z - z_0) f(z)$$For a pole of order $n$, the formula involves the $(n-1)$-th derivative. For $1/z^2$, the pole at 0 has order 2 and residue 0—so the integral around it is zero even though the function blows up there!
What to Try
- $1/z$: Start with the contour away from the origin (integral $\approx 0$), then drag it to enclose the pole. The integral jumps to $2\pi i$.
- $1/(z^2+1)$: The poles are at $\pm i$. Enclose the pole at $i$ (move contour center up) and the integral becomes $\pi$.
- $z^2$ or $e^z$: These are entire functions. The integral is always 0, no matter where the contour is.
- $1/z^2$: Enclose the pole at 0. The integral is still 0! A second-order pole has residue 0.
- $\tan(z)$: Poles at odd multiples of $\pi/2$. Enclose one, two, or more.