Skip to content
Tutorials Center
My learning

Topics

Lesson 31 of 36 · Applications and Conformal Maps

Evaluating Real Integrals with Residues

Use the residue theorem to evaluate improper integrals of rational functions, trigonometric integrals over 0 to 2π and Fourier integrals, checked numerically.

One of the most celebrated uses of the residue theorem is something that looks unrelated to complex numbers: computing real integrals such as ∫ dx/(1 + x⁴) over the whole line, which are hard or impossible with elementary antiderivatives. The trick is to see the real integral as part of a closed contour in the complex plane, evaluate the contour integral with residues, and show that the extra pieces vanish.

This lesson covers the three most common types.

Type 1: rational functions over the real line

Goal. Compute I = ∫_(-∞)^∞ P(x)/Q(x) dx where P and Q are polynomials, Q has no real zeros, and deg Q ≥ deg P + 2.

Method. Close the contour with a large semicircle Γ_R in the upper half-plane: the real segment [-R, R] followed by Γ_R from R back to -R. By the residue theorem, for large R

Text
∫_(-R)^R f dx + ∫_(Γ_R) f dz = 2πi · Σ Res(f, a)   over the poles a with Im a > 0

Since deg Q ≥ deg P + 2, we have |f(z)| ≤ C/R² on Γ_R, and the arc has length πR. By the ML inequality, |∫_(Γ_R) f dz| ≤ Cπ/R → 0. Letting R → ∞:

Text
∫_(-∞)^∞ P(x)/Q(x) dx = 2πi · Σ_(Im a > 0) Res(P/Q, a)

Example 1

∫ dx/(x² + 1). The only pole in the upper half-plane is i, with residue 1/(2i). So I = 2πi · 1/(2i) = π. This agrees with arctan(∞) - arctan(-∞) = π.

Example 2

∫ dx/(x⁴ + 1). The roots of z⁴ = -1 are e^(iπ/4), e^(3iπ/4), e^(5iπ/4), e^(7iπ/4). The first two lie in the upper half-plane. At a simple pole a, Res = 1/(4a³) = a/(4a⁴) = -a/4. So

Text
Σ Res = -(e^(iπ/4) + e^(3iπ/4))/4 = -(i√2)/4,    I = 2πi · (-i√2/4) = π√2/2 = π/√2

because e^(iπ/4) + e^(3iπ/4) = i√2.

Example 3

∫ x²/((x² + 1)(x² + 4)) dx. Poles in the upper half-plane: i and 2i. Using P/Q' with Q = x⁴ + 5x² + 4, Q' = 4x³ + 10x: residue at i is (i²)/(4i³ + 10i) = -1/(6i); at 2i: (−4)/(4(−8i) + 20i) = −4/(−12i) = 1/(3i). The sum is -1/(6i) + 2/(6i) = 1/(6i), so I = 2πi/(6i) = π/3.

Type 2: trigonometric integrals over one period

Goal. Compute ∫_0^(2π) R(cos θ, sin θ) dθ, where R is a rational function of cosine and sine.

Method. Put z = e^(iθ), which traverses the unit circle once. Then

Text
cos θ = (z + 1/z)/2,   sin θ = (z - 1/z)/(2i),   dθ = dz/(iz)

and the integral becomes ∮_(|z|=1) F(z) dz for a rational function F, computed with the residues inside the unit circle.

Example 4

∫_0^(2π) dθ/(a + b cos θ) with a > b > 0. We get

Text
∮ [1/(a + b(z + 1/z)/2)] · dz/(iz) = (2/i) ∮ dz/(b z² + 2a z + b)

The roots of bz² + 2az + b are z± = (-a ± √(a² - b²))/b, with product 1. So exactly one root, z₊ (the one with the + sign), has modulus less than 1. Its residue is 2/(i · (2b z₊ + 2a)) = 2/(i · 2√(a² - b²)). Multiplying by 2πi:

Text
∫_0^(2π) dθ/(a + b cos θ) = 2π/√(a² - b²)

For a = 2, b = 1: 2π/√3 ≈ 3.6276.

Type 3: Fourier integrals

Goal. Compute ∫_(-∞)^∞ f(x) cos(kx) dx or with sin(kx), for k > 0 and f a rational function with f(z) → 0 as |z| → ∞.

Method. Integrate f(z) e^(ikz) instead (taking the real or imaginary part at the end). For k > 0 and Im z ≥ 0, |e^(ikz)| = e^(-k Im z) ≤ 1, so the exponential helps, and Jordan's lemma shows the large arc contributes 0 in the limit when f(z) → 0. Again you only sum residues in the upper half-plane:

Text
∫_(-∞)^∞ f(x) e^(ikx) dx = 2πi · Σ_(Im a > 0) Res(f(z) e^(ikz), a)

Example 5

∫ cos x/(x² + 1) dx. With f(z) e^(iz) = e^(iz)/(z² + 1) the pole in the upper half-plane is i, residue e^(i·i)/(2i) = e^(-1)/(2i). So ∫ e^(ix)/(x² + 1) dx = 2πi · e^(-1)/(2i) = π/e, and since the sine part is odd, ∫ cos x/(x² + 1) dx = π/e ≈ 1.1557.

If f has a simple pole on the real axis, the contour has to be indented around it with a small semicircle; the result is a principal value, with a contribution of πi · Res from each pole on the axis. That variant is beyond this lesson.

Try it: Type 1 as a function

The function below receives the coefficients of P and Q (highest power first), finds the roots of Q with np.roots, keeps those in the upper half-plane, and sums P(a)/Q'(a). We compare to a numerical integral from SciPy, which integrates over the whole real line.

Python A residue evaluator for rational integrals

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Try it: Types 2 and 3

For Type 2 we compute the residue inside the unit circle with the formula derived above, and compare with a numerical integral. For Type 3 we use SciPy's oscillatory-integral weight cos(x) on [0, ∞) (the integrand is even, so we double it) and compare with π/e.

Python Trigonometric and Fourier integrals

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Strategy

  1. Identify the type: rational on (-∞, ∞), a trigonometric function over [0, 2π], or a Fourier integral.
  2. Choose the contour: a semicircle for the first and third, the unit circle for the second.
  3. Check that the extra piece vanishes (ML for Type 1, Jordan for Type 3).
  4. Find the poles inside, compute the residues with the residue formulas, sum and multiply by 2πi.
  5. Take the real part if needed and check the sign, since a positive integrand must give a positive answer.

Check your understanding

Quick check · 4 questions

of 4 answered You scored / 4 · perfect!

  1. 1. For ∫ P/Q dx over the real line to be computed by a large upper semicircle, what degree condition is needed?

    Then |f| ≤ C/R² on the arc of length πR, so the arc integral tends to 0.
  2. 2. What is ∫ dx/(x² + 1) over the real line, by residues?

    The residue at i is 1/(2i), so the integral is 2πi · 1/(2i) = π.
  3. 3. In the substitution z = e^(iθ), dθ equals

    dz = i e^(iθ) dθ = iz dθ, so dθ = dz/(iz).
  4. 4. To evaluate ∫ cos(x) f(x) dx with a contour in the upper half-plane we integrate

    e^(iz) decays in the upper half-plane, so Jordan's lemma lets the arc vanish; take the real part at the end.

Summary

  • Rational integrals over R with deg Q ≥ deg P + 2: 2πi times the sum of residues in the upper half-plane.
  • Trigonometric integrals over [0, 2π]: put z = e^(iθ) and sum residues inside the unit circle.
  • Fourier integrals: use f(z) e^(ikz) and Jordan's lemma, then take real or imaginary parts.
  • ∫ dx/(1 + x⁴) = π/√2, ∫_0^(2π) dθ/(2 + cos θ) = 2π/√3, ∫ cos x/(1 + x²) dx = π/e.

Next: The argument principle and Rouché's theorem