Pole on a contour. Problem with integration I have a problem with calculation of the complex integral
$$\int_{|z|=1}\frac{z^2+3z+2i}{(z+4)(z-1)}dz$$
Apparently integrand has a pole in $1$ lying on our circle. What can I do? I cant use Cauchy formula here...
 A: Consider the contour where we have a small half circle around $z=1$ of radius $\epsilon$ excluding $1$ and the a circle around the origin. Since there are no poles in the contour, we have by Cauchy's integral formula
$$
\int_{\lvert z\rvert = 1}\frac{z^2+3z+2i}{(z+4)(z-1)}dz=0
$$

We can break the contour up into
\begin{align}
\int_{\lvert z\rvert = 1}\frac{z^2+3z+2i}{(z+4)(z-1)}dz &=
\int_{-\pi/2}^{-\epsilon}\frac{z^2+3z+2i}{(z+4)(z-1)}dz + \int_{\pi}^0\frac{(\epsilon e^{i\theta}+1)^2+3(\epsilon e^{i\theta}+1)+2i}{[(\epsilon e^{i\theta}+1)+4][(\epsilon e^{i\theta}+1)-1]}i\epsilon d\theta\\
&+ \int_{\epsilon}^{3\pi/2}\frac{z^2+3z+2i}{(z+4)(z-1)}dz
\end{align}
Taking the limit as epsilon goes to zero, we obtain
$$
\int_{\lvert z\rvert = 1}\frac{z^2+3z+2i}{(z+4)(z-1)}dz+\lim_{\epsilon\to 0}\int_{\pi}^0\frac{(\epsilon e^{i\theta}+1)^2+3(\epsilon e^{i\theta}+1)+2i}{[(\epsilon e^{i\theta}+1)+4][(\epsilon e^{i\theta}+1)-1]}i\epsilon d\theta=0
$$
The reason $z=1+\epsilon e^{i\theta}$ was plugged in for the small arc is because we have a half circle of radius epsilon shifted around $z=1$. The bounds of $(\pi,0)$ were chosen, because if we are moving counter clockwise, we would have $\int_{-\pi/2}^{\pi/2}=\int_{\pi}^0$. We now have
\begin{align}
\int_{\lvert z\rvert = 1}\frac{z^2+3z+2i}{(z+4)(z-1)}dz &=\lim_{\epsilon\to 0}\int_0^{\pi}\frac{(\epsilon e^{i\theta}+1)^2+3(\epsilon e^{i\theta}+1)+2i}{[(\epsilon e^{i\theta}+1)+4][(\epsilon e^{i\theta}+1)-1]}i\epsilon d\theta\\
&=i\lim_{\epsilon\to 0}\int_0^{\pi}\frac{\epsilon^2 e^{2i\theta} + 5\epsilon e^{i\theta}+4+2i}{\epsilon e^{i\theta} + 5}d\theta\\
&= i\int_0^{\pi}\lim_{\epsilon\to 0}\frac{\epsilon^2 e^{2i\theta} + 5\epsilon e^{i\theta}+4+2i}{\epsilon e^{i\theta} + 5}d\theta\\
&= i\int_0^{\pi}\frac{4+2i}{5}d\theta\tag{1}\\
&=\frac{i\pi}{5}(4+2i)\\
&= i\pi\sum\text{Res}\{f(z);z=1\}
\end{align}
From $(1)$, you see that with only the half circle, we pick up $\pi$ whereas a full circle picks up $2\pi$.
A: Let $\gamma=\gamma_0+\gamma_r$:

where $\gamma_r$ is a semicircle, $\oint_{\gamma_0}$ is zero bu Cauchy-Goursat Theorem. So the value is $\frac12\lim_{r\to0}\oint_{\gamma_r}\frac{f(z)}{z-1}{\rm d}z$ where $f(z)=\frac{z^2+3z+2i}{z+4}$, so after substituting $z=1+re^{i\theta}$ you'll see the value is $\frac12(2\pi if(1))=\pi if(1)$ where $f(1)$ is actually $\operatorname{Res}_{z=1}\frac{f(z)}{z-1}$
A: Here is an intuitive explanation of how to deal with a pole that is on the contour.
First, define a new contour that deviates slightly from the original one in a small semi-circle with the pole at the center so that you slightly avoid the problematic pole on the contour. Since there are no poles on this new contour, we will have an easier time evaluating the integral along it. But we were supposed to evaluate the integral along the original contour, not a deformed one. What should we do?
The two contours differ in two ways. The new contour does not have the part which actually crosses the pole. And it has an extra part, the semi-circle that avoids the pole. In the integral, we just need to manually add and subtract the effects of these two parts, respectively. Do it manually, and we are done.
Now, there is a catch. That is, often, one can pull this off and get a reasonable answer. But sometimes, the pole on the contour causes the integral to diverge. Consider the following divergent integral, for example-
$$\int_{-a} ^a \frac{1}{x^2} dx$$
So, when will the pole on the contour be harmless and when will it be lethal?
Intuitively, whenever your pole is of the order of an odd number, then the contribution due to the pole cancels off, in some sense, like following-
$$\int_{-a} ^a \frac{1}{x^{2n+1}}dx=0 $$
for all positive integers n.
More precisely, let
$$f(z)=\sum_{n=-\infty}^{n=\infty} \alpha_n (z-a)^n$$
be the function in question and $a$ be the point on the contour with the pole. Then the integral will diverge if for any integer $n\geq 0$, there exists $\alpha_{-2n-2}\neq0$. That is, in this case the part of the contour actually passing through the pole contributes an infinity and there is nothing you can do about it.
Now, if for all $n\geq 0$, $\alpha_{-2n-2}=0$, then the part of the contour that crosses the pole does not contribute anything to the integral, because, in some sense,
$$\int_{-a} ^a \frac{1}{x^{2n+1}}dx=0 , \forall n\geq0$$
Also, it can be checked that, in this case, subtracting the contribution of the corresponding semicircle part will contribute a grand total of $i \pi \alpha_{-1}$ to the integral, that is, $i \pi$ times half of the residue from the pole.
That is, in this case, the higher order odd singularities will not contribute anything to the semi-circle part.
