complex contour integral with poles I really need help with a complex integral.
$\displaystyle{\int_{|{z-1}|=3}\dfrac{dz}{z(z^2-4)e^z}\,dz}$.
This one. Could you please help me and solve this showing me the passages and the result? I should be able to solve this with Cauchy's formula or the residue theorem, but i have problems with poles on the contour, how do I deal with them?
 A: Let
$$f(z) = \frac1{z(z^2 - 4)e^z}$$
be your integrand.
Due to the presence of the pole on the contour, this integral doesn't exist as such, and the conditions of the residue theorem don't apply either. However, around the simple pole at $-2$, the function is antisymmetric to first order and by symmetrically taking a limit as an improper integral, you get the  Cauchy principal value
$$PV\int_{|z-1| = 3}f(z)dz$$
which is well-defined for this integral. Let's assume this is the integral you want to compute.
Now consider the following closed contour $\Gamma$, made up of a segment $\Gamma_\varepsilon$ equal to your original contour except for a disk of radius $\varepsilon$ around $-2$, and a segment of a circle of radius $\varepsilon$ around $-2$ closing it off:

Then we have
$$PV\int_{|z-1| = 3}f(z)dz = \lim_{\varepsilon\to0}\int_{\Gamma_\varepsilon}f(z)dz.$$
The enclosed poles are $0$ and $2$, where the residues are $-\frac14$ and $\frac{e^{-2}}8$, so by the residue theorem we have
$$\int_{\Gamma_\varepsilon}f(z)dz = \int_{\Gamma}f(z)dz - \int_{\gamma_\varepsilon}f(z)dz = 2\pi i\left(\frac{e^{-2}}8 - \frac14\right) - \int_{\gamma_\varepsilon}f(z)dz.$$
In the limit for $\varepsilon\to 0$, the regular part of $f$ doesn't contribute to the integral over $\gamma_\varepsilon$, and since the residue at $-2$ is $\frac{e^2}8$, the integral over the semicircle in the limit is $-\pi i\frac{e^2}8$, the minus sign because it is followed in clockwise direction.
From this we get the value
$$PV\int_{|z-1| = 3}f(z)dz = \pi i\left(\frac{e^{-2}}4 - \frac12 + \frac{e^2}{8}\right).$$
EDIT
Let's check this numerically: parameterize the contour as
$$\gamma(\theta) = 3e^{i\theta} + 1.$$
Then
$$PV\int_{|z-1| = 3}f(z)dz = \lim_{\varepsilon\to0}\int_{-\pi + \varepsilon}^{\pi - \varepsilon}f(\gamma(\theta))\gamma'(\theta)d\theta.$$
Evaluation using Python with mpmath:
from mpmath import quad
from cmath import exp, pi

def f(z):
    return 1 / (z * (z**2 - 4) * exp(z))

def g(t):
    return f(3*exp(t * 1j) + 1) * 3j * exp(t * 1j)

def pv(eps):
    return complex(quad(g, [-pi + eps, pi - eps]))

print(pv(1e-6), pi * 1j * (exp(-2)/4 - .5 + exp(2)/8))

This outputs
1.437168991707318j 1.437171300772436j

