MATH-334 · Lesson 11 of 12 · 31 min
Evaluating real integrals with residues
One of the first great successes of complex analysis, and still one of its most used, is the evaluation of definite real integrals. Integrals such as \(\int_{-\infty}^{\infty}\frac{dx}{1 + x^4}\), \(\int_0^{\infty}\frac{\sin x}{x}\,dx\) or \(\int_0^{2\pi}\frac{d\theta}{2 + \cos\theta}\) have no elementary antiderivative or a very awkward one, yet the residue theorem gives their values in a few lines. The method is always the same: choose a complex function and a closed contour so that part of the contour integral is the real integral you want, compute the contour integral by residues, and show that the remaining parts vanish or are related to the original. This lesson works through the four standard types and checks every answer against numerical quadrature.
Type 1: trigonometric integrals over a full period
For an integral \(\int_0^{2\pi}R(\cos\theta, \sin\theta)\,d\theta\) with \(R\) a rational function, put \(z = e^{i\theta}\). As \(\theta\) runs from 0 to \(2\pi\), \(z\) traverses the unit circle once, and
\[\cos\theta = \frac{1}{2}\Big(z + \frac{1}{z}\Big), \qquad \sin\theta = \frac{1}{2i}\Big(z - \frac{1}{z}\Big), \qquad d\theta = \frac{dz}{iz}.\]
The integral becomes the integral of a rational function of \(z\) round the unit circle, which is \(2\pi i\) times the sum of its residues inside.
Worked problem
A trigonometric integral
Evaluate \(I = \int_0^{2\pi}\frac{d\theta}{2 + \cos\theta}\).
Show solution
- Substitute: \(2 + \frac{1}{2}(z + z^{-1}) = \frac{z^2 + 4z + 1}{2z}\), so \(I = \oint_{|z| = 1}\frac{2z}{z^2 + 4z + 1}\cdot\frac{dz}{iz} = \frac{2}{i}\oint\frac{dz}{z^2 + 4z + 1}\).
- The roots of \(z^2 + 4z + 1\) are \(-2 \pm \sqrt{3}\). Only \(z_1 = -2 + \sqrt{3} \approx -0.268\) is inside the unit circle.
- Residue at \(z_1\): \(\frac{1}{2z_1 + 4} = \frac{1}{2\sqrt{3}}\).
- So \(I = \frac{2}{i}\cdot 2\pi i\cdot\frac{1}{2\sqrt{3}} = \frac{2\pi}{\sqrt{3}}\).
Answer: \(\frac{2\pi}{\sqrt{3}} \approx 3.6276\). More generally \(\int_0^{2\pi}\frac{d\theta}{a + b\cos\theta} = \frac{2\pi}{\sqrt{a^2 - b^2}}\) for \(a > |b|\).
Type 2: rational functions on the real line
Let \(f = \frac{p}{q}\) be a rational function with \(q\) having no real zeros and \(\deg q \ge \deg p + 2\). Then \(\int_{-\infty}^{\infty}f(x)\,dx\) converges absolutely. Take the contour consisting of the segment \([-R, R]\) and the semicircle \(S_R\): \(z = Re^{it}\), \(0 \le t \le \pi\), in the upper half-plane. For \(R\) large enough to enclose all poles of \(f\) in the upper half-plane,
\[\int_{-R}^{R}f(x)\,dx + \int_{S_R}f(z)\,dz = 2\pi i\sum_{\operatorname{Im} z_k > 0}\operatorname{Res}(f, z_k).\]
The degree condition gives \(|f(z)| \le \frac{K}{R^2}\) on \(S_R\) for large \(R\), so by the ML inequality \(|\int_{S_R}f\,dz| \le \frac{K}{R^2}\pi R \to 0\). Letting \(R \to \infty\),
\[\int_{-\infty}^{\infty}f(x)\,dx = 2\pi i\sum_{\operatorname{Im} z_k > 0}\operatorname{Res}(f, z_k).\]
Worked problem
A rational integral
Evaluate \(\int_{-\infty}^{\infty}\frac{dx}{1 + x^4}\).
Show solution
- The poles are the fourth roots of \(-1\): \(e^{i\pi/4}, e^{3i\pi/4}, e^{5i\pi/4}, e^{7i\pi/4}\). The first two are in the upper half-plane.
- At a simple pole \(z_k\) the residue is \(\frac{1}{4z_k^3} = \frac{z_k}{4z_k^4} = -\frac{z_k}{4}\), since \(z_k^4 = -1\).
- Sum: \(-\frac{1}{4}(e^{i\pi/4} + e^{3i\pi/4}) = -\frac{1}{4}\cdot i\sqrt{2} = -\frac{i\sqrt{2}}{4}\).
- Multiply by \(2\pi i\): \(2\pi i\cdot\big(-\frac{i\sqrt{2}}{4}\big) = \frac{\pi\sqrt{2}}{2}\).
Answer: \(\frac{\pi}{\sqrt{2}} \approx 2.2214\).
Type 3: Fourier integrals and Jordan's lemma
Integrals \(\int_{-\infty}^{\infty}f(x)\cos(ax)\,dx\) and \(\int_{-\infty}^{\infty}f(x)\sin(ax)\,dx\), with \(a > 0\), are the real and imaginary parts of \(\int_{-\infty}^{\infty}f(x)e^{iax}\,dx\). We use \(e^{iaz}\), not \(\cos az\), because \(|e^{iaz}| = e^{-ay}\) is at most 1 in the upper half-plane, whereas \(\cos az\) grows exponentially there. When \(\deg q \ge \deg p + 2\), the semicircle argument above works unchanged. When \(\deg q = \deg p + 1\) the ML bound is not enough, and we need a sharper estimate.
Jordan's lemma. If \(|f(z)| \le M_R\) on \(S_R\) and \(M_R \to 0\), then \(\int_{S_R}f(z)e^{iaz}\,dz \to 0\) for \(a > 0\).
Proof. On \(S_R\), \(|e^{iaz}| = e^{-aR\sin t}\), so the integral is at most \(M_RR\int_0^\pi e^{-aR\sin t}\,dt = 2M_RR\int_0^{\pi/2}e^{-aR\sin t}\,dt\). On \([0, \frac{\pi}{2}]\), concavity gives \(\sin t \ge \frac{2t}{\pi}\), so the last integral is at most \(\int_0^{\infty}e^{-2aRt/\pi}\,dt = \frac{\pi}{2aR}\). The bound is \(\frac{\pi M_R}{a} \to 0\). \(\square\)
Worked problem
A Fourier integral
Evaluate \(\int_{-\infty}^{\infty}\frac{\cos x}{x^2 + 1}\,dx\).
Show solution
- Consider \(\frac{e^{iz}}{z^2 + 1}\) with the semicircle in the upper half-plane. The only pole inside is \(z = i\).
- Residue at \(i\): \(\frac{e^{i \cdot i}}{2i} = \frac{e^{-1}}{2i}\).
- The semicircle integral vanishes by the ML inequality (or Jordan). So \(\int\frac{e^{ix}}{x^2 + 1}\,dx = 2\pi i\cdot\frac{e^{-1}}{2i} = \frac{\pi}{e}\).
- Take real parts. (The imaginary part, \(\int\frac{\sin x}{x^2 + 1}\,dx\), is 0 because the integrand is odd.)
Answer: \(\frac{\pi}{e} \approx 1.1557\).
Indented contours: the Dirichlet integral
Sometimes the integrand has a pole on the real axis. The classical example is \(\int_0^{\infty}\frac{\sin x}{x}\,dx\), which Euler had evaluated by other means and which now carries Dirichlet's name. Consider \(\frac{e^{iz}}{z}\), which has a simple pole at 0. Use the contour: \([-R, -\varepsilon]\), the small semicircle \(C_\varepsilon\) of radius \(\varepsilon\) above 0 traversed clockwise, \([\varepsilon, R]\), and the large semicircle \(S_R\). No poles are inside, so the total is 0.
By Jordan's lemma the integral over \(S_R\) tends to 0. On the small semicircle, \(\frac{e^{iz}}{z} = \frac{1}{z} + g(z)\) with \(g\) analytic, so the integral of \(g\) tends to 0 (ML), and \(\int\frac{dz}{z}\) over a clockwise half-circle is \(-i\pi\). Hence
\[\lim\Big(\int_{-R}^{-\varepsilon} + \int_{\varepsilon}^{R}\Big)\frac{e^{ix}}{x}\,dx = i\pi.\]
The real part of the integrand, \(\frac{\cos x}{x}\), is odd and cancels; the imaginary part gives \(2\int_0^{\infty}\frac{\sin x}{x}\,dx = \pi\). So
\[\int_0^{\infty}\frac{\sin x}{x}\,dx = \frac{\pi}{2}.\]
In general, a small semicircle round a simple pole contributes \(-i\pi\) times the residue when traversed clockwise, half of what a full circle would give.
The same idea gives Cauchy principal values of integrals that do not converge in the ordinary sense. For \(f\) rational with simple poles \(x_j\) on the real axis, poles \(z_k\) in the upper half-plane, and \(\deg q \ge \deg p + 2\), indenting round each real pole gives
\[\operatorname{PV}\int_{-\infty}^{\infty}f(x)\,dx = 2\pi i\sum_k\operatorname{Res}(f, z_k) + \pi i\sum_j\operatorname{Res}(f, x_j).\]
For example, \(f(z) = \frac{1}{z(z^2 + 1)}\) has a simple pole at 0 with residue 1 and a pole at \(i\) with residue \(\frac{1}{i \cdot 2i} = -\frac{1}{2}\). The formula gives \(2\pi i(-\frac{1}{2}) + \pi i(1) = 0\), which is correct, since the integrand is odd.
Type 4: branch cuts and the keyhole contour
For integrals of the form \(\int_0^{\infty}x^{a-1}f(x)\,dx\) with non-integer \(a\), or with a logarithm, the integrand has a branch point at 0. Cut the plane along the positive real axis, using the branch of \(z^{a-1} = e^{(a-1)\log z}\) with \(0 < \arg z < 2\pi\). The keyhole contour runs along the top of the cut from \(\varepsilon\) to \(R\), round the large circle counterclockwise, back along the bottom of the cut from \(R\) to \(\varepsilon\), and round a small circle clockwise.
Worked problem
A keyhole integral
Show that \(\int_0^{\infty}\frac{x^{a-1}}{1 + x}\,dx = \frac{\pi}{\sin\pi a}\) for \(0 < a < 1\).
Show solution
- Take \(f(z) = \frac{z^{a-1}}{1 + z}\). Its only pole is \(z = -1 = e^{i\pi}\), with residue \(e^{i\pi(a-1)} = -e^{i\pi a}\).
- On the top of the cut \(z^{a-1} = x^{a-1}\). On the bottom, \(\arg z = 2\pi\), so \(z^{a-1} = x^{a-1}e^{2\pi i(a-1)} = x^{a-1}e^{2\pi ia}\), traversed from \(R\) to \(\varepsilon\).
- On the large circle \(|f| \le \frac{R^{a-1}}{R - 1}\), so the ML bound \(\frac{2\pi R^a}{R - 1} \to 0\) because \(a < 1\). On the small circle \(|f| \le \frac{\varepsilon^{a-1}}{1 - \varepsilon}\) and the bound \(\frac{2\pi\varepsilon^a}{1 - \varepsilon} \to 0\) because \(a > 0\).
- So \((1 - e^{2\pi ia})I = 2\pi i(-e^{i\pi a})\), giving \(I = \frac{-2\pi ie^{i\pi a}}{1 - e^{2\pi ia}} = \frac{2\pi i}{e^{i\pi a} - e^{-i\pi a}} = \frac{\pi}{\sin\pi a}\).
Answer: \(\frac{\pi}{\sin\pi a}\). With \(a = \frac{1}{2}\), \(\int_0^\infty\frac{dx}{\sqrt{x}(1 + x)} = \pi\), which can be checked by the substitution \(x = t^2\).
Rectangular contours
Integrands involving exponentials are often periodic in the imaginary direction, and then a rectangle replaces the semicircle. Consider \(I = \int_{-\infty}^{\infty}\frac{e^{ax}}{1 + e^x}\,dx\) for \(0 < a < 1\), which converges because the integrand decays like \(e^{ax}\) as \(x \to -\infty\) and like \(e^{(a-1)x}\) as \(x \to \infty\). Take \(f(z) = \frac{e^{az}}{1 + e^z}\) and the rectangle with vertices \(\pm R\) and \(\pm R + 2\pi i\).
On the top edge, \(z = x + 2\pi i\), the denominator is unchanged because \(e^{2\pi i} = 1\), while the numerator gains a factor \(e^{2\pi ia}\). Traversed from right to left, the top edge contributes \(-e^{2\pi ia}\int_{-R}^{R}\frac{e^{ax}}{1 + e^x}\,dx\). On the vertical sides the integrand is bounded by \(\frac{e^{aR}}{e^R - 1}\) or by \(\frac{e^{-aR}}{1 - e^{-R}}\), and the sides have length \(2\pi\), so they vanish as \(R \to \infty\).
Inside the rectangle the only pole is where \(e^z = -1\), at \(z = i\pi\). It is simple, with residue \(\frac{e^{ai\pi}}{e^{i\pi}} = -e^{i\pi a}\). The residue theorem gives \((1 - e^{2\pi ia})I = -2\pi ie^{i\pi a}\), and so \(I = \frac{\pi}{\sin\pi a}\), the same value as the keyhole integral. That is no coincidence: the substitution \(x = \ln t\) turns one integral into the other.
Choosing a method
In practice the shape of the integrand picks the contour. A full period of a trigonometric expression suggests the unit circle. A rational function on the whole line, possibly multiplied by \(e^{iax}\), suggests a large semicircle, in the upper half-plane for \(a > 0\) and the lower for \(a < 0\), where the orientation reverses the sign. An integral over \([0, \infty)\) of an even function can be doubled into one over the line. A fractional power or a logarithm calls for a keyhole round the branch cut. And an exponential that is periodic in \(y\) calls for a rectangle. In every case, the only real work beyond computing residues is to show that the unwanted pieces vanish, and the ML inequality and Jordan's lemma handle almost every situation.
import cmath, math
def simpson(g, a, b, n=20000):
h = (b - a) / n
s = g(a) + g(b)
for k in range(1, n):
s += (4 if k % 2 else 2) * g(a + k*h)
return s * h / 3
# Type 1: map [0, 2*pi]; the integrand is smooth and periodic.
num = simpson(lambda t: 1/(2 + math.cos(t)), 0, 2*math.pi)
print(f"int 1/(2+cos t): quadrature {num:.10f} residues {2*math.pi/math.sqrt(3):.10f}")
# Types 2 and 3: map the real line to (-pi/2, pi/2) by x = tan u, dx = sec^2 u du.
def real_line(f, n=20000):
e = 1e-9
return simpson(lambda u: f(math.tan(u)) / math.cos(u)**2, -math.pi/2 + e, math.pi/2 - e, n)
print(f"int 1/(1+x^4): quadrature {real_line(lambda x: 1/(1 + x**4)):.10f} residues {math.pi/math.sqrt(2):.10f}")
print(f"int cos x/(x^2+1): quadrature {simpson(lambda x: math.cos(x)/(x*x + 1), -200*math.pi, 200*math.pi, 400000):.8f} residues {math.pi/math.e:.8f}")
# Dirichlet integral: integrate sin(x)/x over [0, N*pi] and average two partial results.
si = lambda x: math.sin(x)/x if x else 1.0
a = simpson(si, 0, 2000*math.pi, 400000); b = simpson(si, 0, 2001*math.pi, 400000)
print(f"int_0^inf sin x / x: quadrature {(a + b)/2:.6f} residues {math.pi/2:.6f}")
# Keyhole example with a = 1/2: substitute x = t^2 to remove the singularity at 0.
val = real_line(lambda t: 2/(1 + t*t)) / 2 # integral over t > 0 of 2/(1+t^2)
print(f"int x^(-1/2)/(1+x): quadrature {val:.8f} residues {math.pi/math.sin(math.pi/2):.8f}")
# The residue side computed with cmath, for 1/(1+x^4).
poles = [cmath.exp(1j*math.pi*(2*k + 1)/4) for k in range(4)]
upper = [p for p in poles if p.imag > 0]
print("2*pi*i * sum of residues:", 2j*math.pi*sum(1/(4*p**3) for p in upper))int 1/(2+cos t): quadrature 3.6275987285 residues 3.6275987285 int 1/(1+x^4): quadrature 2.2214414691 residues 2.2214414691 int cos x/(x^2+1): quadrature 1.15572733 residues 1.15572735 int_0^inf sin x / x: quadrature 1.570796 residues 1.570796 int x^(-1/2)/(1+x): quadrature 3.14159265 residues 3.14159265 2*pi*i * sum of residues: (2.221441469079183+5.231802747012948e-16j)
Common mistakes
Common mistakes
MistakeUsing \(\cos z\) instead of \(e^{iz}\) for a Fourier integral.
Instead\(\cos z\) grows like \(e^{|y|}\) off the real axis, so the semicircle contribution does not vanish; use \(e^{iz}\) and take real or imaginary parts.
MistakeIncluding poles in the lower half-plane when closing in the upper half-plane.
InsteadOnly poles enclosed by the contour count.
MistakeForgetting the factor \(\frac{1}{iz}\) from \(d\theta\).
InsteadWith \(z = e^{i\theta}\), \(d\theta = \frac{dz}{iz}\).
MistakeAssuming the large arc always vanishes.
InsteadCheck: the ML inequality needs \(|zf(z)| \to 0\); Jordan's lemma needs \(f \to 0\) and a factor \(e^{iaz}\) with \(a > 0\).
MistakeUsing the same value of \(x^{a-1}\) on both sides of a branch cut.
InsteadOn the lower edge the argument is \(2\pi\), contributing a factor \(e^{2\pi i(a-1)}\).
Summary and key terms
- Integrals over \([0, 2\pi]\) of rational functions of \(\cos\theta, \sin\theta\) become unit-circle integrals with \(z = e^{i\theta}\).
- For rational \(f\) with \(\deg q \ge \deg p + 2\), \(\int_{-\infty}^{\infty}f = 2\pi i\sum\) residues in the upper half-plane.
- Fourier integrals use \(e^{iaz}\) and Jordan's lemma to dispose of the large semicircle.
- A pole on the real axis is bypassed by a small semicircle contributing \(-i\pi\) times its residue.
- Branch points are handled with keyhole contours, where the two edges of the cut differ by a factor from the branch.
- Semicircular contour
- The segment \([-R, R]\) closed by a half-circle of radius \(R\) in the upper half-plane.
- Jordan's lemma
- \(\int_{S_R}f(z)e^{iaz}\,dz \to 0\) when \(a > 0\) and \(\max_{S_R}|f| \to 0\).
- Indented contour
- A contour detouring round a pole on the path by a small semicircle.
- Keyhole contour
- Large and small circles joined along both edges of a branch cut.
- Principal value
- The symmetric limit \(\lim_{\varepsilon \to 0}\big(\int_{-R}^{-\varepsilon} + \int_{\varepsilon}^{R}\big)\) used across a pole.
Practice problems
Work each problem on paper first, then reveal the answer to check.
Evaluate \(\int_0^{2\pi}\frac{d\theta}{5 - 4\cos\theta}\).
Show answer
\(\frac{2\pi}{\sqrt{25 - 16}} = \frac{2\pi}{3}\).
Evaluate \(\int_{-\infty}^{\infty}\frac{dx}{(x^2 + 1)^2}\).
Show answer
Double pole at \(i\): residue \(\frac{d}{dz}(z + i)^{-2}\big|_i = -2(2i)^{-3} = \frac{1}{4i}\). The integral is \(\frac{\pi}{2}\).
Evaluate \(\int_{-\infty}^{\infty}\frac{x\sin x}{x^2 + 4}\,dx\).
Show answer
Imaginary part of \(2\pi i\operatorname{Res}\big(\frac{ze^{iz}}{z^2 + 4}, 2i\big) = 2\pi i\cdot\frac{e^{-2}}{2} = \pi ie^{-2}\); the answer is \(\frac{\pi}{e^2}\), using Jordan's lemma.
Evaluate \(\int_{-\infty}^{\infty}\frac{dx}{x^2 + 2x + 2}\).
Show answer
Pole at \(-1 + i\) with residue \(\frac{1}{2i}\); the integral is \(\pi\).
Evaluate \(\int_0^\infty\frac{x^{-1/3}}{1 + x}\,dx\).
Show answer
With \(a = \frac{2}{3}\): \(\frac{\pi}{\sin(2\pi/3)} = \frac{2\pi}{\sqrt{3}}\).
Evaluate \(\int_0^{\infty}\frac{dx}{x^6 + 1}\).
Show answer
Half the integral over the line. The upper poles are \(e^{i\pi/6}, i, e^{5i\pi/6}\), with residues \(-\frac{z_k}{6}\); their sum is \(-\frac{2i}{6}\), so the full integral is \(\frac{2\pi}{3}\) and the answer is \(\frac{\pi}{3}\).
Use a rectangle of height \(2\pi\) to evaluate \(\int_{-\infty}^{\infty}\frac{e^{x/2}}{1 + e^x}\,dx\).
Show answer
This is the case \(a = \frac{1}{2}\): \(\frac{\pi}{\sin(\pi/2)} = \pi\). Directly, \(\frac{e^{x/2}}{1 + e^x} = \frac{1}{2\cosh(x/2)}\), whose integral is \(\pi\).
Lesson quiz · 5 questions
Score 60% or more to complete this lesson.
Create a free account to save your progress, take quizzes and earn a certificate.