Complex Analysis Example: Contour Integration Using Residue Theorem
One of the fundamental topics in complex analysis is contour integration, specifically using the residue theorem to evaluate integrals.
Problem Statement
Evaluate the contour integral:
$$
\oint_C \frac{e^z}{z^2 + 1} dz
$$
where $ C $ is the counterclockwise unit circle $( |z| = 1 )$.
Solution Approach
Identify Singularities
The denominator $( z^2 + 1 = 0 )$ has roots at:
$$
z = \pm i
$$
These are the singularities (poles). We check which are inside the contour $( |z| = 1 )$:- $( z = i )$ is inside.
- $( z = -i )$ is outside.
Find the Residue at $( z = i )$
The function can be rewritten as:
$$
f(z) = \frac{e^z}{(z - i)(z + i)}
$$
The residue at $( z = i )$ is given by:
$$
\text{Res}(f, i) = \lim_{z \to i} (z - i) f(z)
$$Use the Residue Theorem
The theorem states that for a simple pole inside the contour,
$$
\oint_C f(z) dz = 2\pi i \cdot \text{Res}(f, i)
$$
We compute this residue and use it to evaluate the integral.
Python Implementation
We’ll:
- Compute the residue symbolically using SymPy.
- Numerically verify the integral using SciPy.
- Visualize the function and contour using Matplotlib.
Let’s write the code.
1 | import numpy as np |
Explanation of the Code
Symbolic Computation
- We define $ f(z) = \frac{e^z}{z^2 + 1} $ using
SymPy. - We compute the residue at $( z = i )$ using
sp.residue(). - We apply the residue theorem to compute the contour integral.
- We define $ f(z) = \frac{e^z}{z^2 + 1} $ using
Numerical Computation and Visualization
- We create a mesh grid in the complex plane.
- We evaluate the function $ f(z) $ and plot magnitude and phase contours.
- We overlay the unit circle to show the integration path.
Results

Residue at z=i: -I*exp(I)/2 Contour Integral Value: 1.69740975483297 + 2.64355906408146*I
- The computed residue and integral value are printed.
- A contour plot of $ f(z) $ in the complex plane is displayed.
This method visually and computationally confirms the result using complex analysis techniques and $Python$.









