Why complex?
Complex numbers are not a bookkeeping trick reserved for electrical engineers. In physics, writing an oscillation as e^{i\omega t} instead of \cos\omega t turns calculus into algebra: differentiating just multiplies by i\omega. A function of a complex variable f(z), where z=x+iy, carries far more structure than a function of a real variable — and that extra structure is exactly what lets us evaluate integrals, sum series, and understand resonances.
Analytic functions and Cauchy-Riemann
A function is analytic (holomorphic) at a point if it is complex-differentiable there — the limit defining $f'(z)$ must give the same answer no matter which direction in the plane you approach along. That is a severe demand, and it forces a pair of conditions on the real and imaginary parts f=u+iv: the Cauchy-Riemann equations.
The Cauchy-Riemann equations. A consequence: both u and v are harmonic, so analytic functions solve Laplace's equation — the link to electrostatics and 2D fluid flow.
Analyticity is almost magical: if a function is analytic in a region, it is automatically infinitely differentiable there, and its values on any small loop determine its values everywhere inside — the content of Cauchy's integral formula. Real functions enjoy no such rigidity.
Cauchy's theorem, poles, and residues
The foundation is Cauchy's theorem: the integral of an analytic function around any closed loop is zero. Everything interesting therefore comes from the places where a function fails to be analytic — its poles, points where it blows up like 1/(z-z_0). Near such a point a function has a Laurent series, and the coefficient of the 1/(z-z_0) term is called the residue.
The residue theorem: a closed contour integral equals 2πi times the sum of residues at the poles it encloses. Integration becomes counting.
For a simple pole the residue is easy to extract: \operatorname{Res}_{z_0} f=\lim_{z\to z_0}(z-z_0)\,f(z). For a function written as a ratio g/h with a simple zero of h at z_0, it is simply g(z_0)/h'(z_0).
A worked example
Consider a real integral that resists elementary methods: \displaystyle\int_{-\infty}^{\infty}\frac{dx}{x^2+a^2} with a>0. Contour integration dispatches it in a few clean steps.
- Extend to the complex plane. View the integrand as f(z)=1/(z^2+a^2)=1/[(z-ia)(z+ia)], with simple poles at z=\pm ia.
- Close the contour with a large semicircle in the upper half-plane. As its radius R\to\infty the arc contributes nothing, because $|f|$ falls off like 1/R^2 while the arc length grows only like R.
- Find the enclosed residue. Only the pole at z=+ia lies inside. Using $g/h'$ with h=z^2+a^2 and h'=2z, its residue is $1/(2ia)$.
- Apply the residue theorem. The integral equals 2\pi i\cdot 1/(2ia)=\pi/a. The real integral is read off directly.
The result. You can check it against the elementary answer (1/a)·arctan(x/a) — but the contour method generalises to integrals with no elementary antiderivative at all.
Branch cuts and a caution
Not every non-analytic feature is a pole. Functions like \sqrt{z} or \ln z are multivalued — going once around the origin does not bring you back to the same value. We tame them with a branch cut, a forbidden line the contour may not cross, which pins down a single-valued branch. Contours must then be routed around these cuts, a standard but delicate technique.