TITLE: A complex function integral
QUESTION [7 upvotes]: I got a problem in an exam.
We need to caculate following limit:

$$\lim_{x\rightarrow \infty} \int_{L_x}\frac{\cos z}{z^2+1} dz,$$
  where $L_x$ is the line from $-x+2i$ to $x+2i$.

Of course we can calculate the integrals of the real part and imaginary part seperately. But it would be extremely complicated. I think it can't be the right solution since it wouldn't be done in the time of an exam.

REPLY [4 votes]: Let us consider a rectangle $\gamma_R$ with vertices at $-R,R,R+2i,-R+2i$, counter-clockwise oriented, with $R\gg 1$and $f(z)=\frac{\cos(z)}{z^2+1}$. By the ML lemma and the residue theorem
$$\begin{eqnarray*}\oint_{\gamma_R}f(z)\,dz &=& \int_{-R}^{+R}\frac{\cos(z)}{z^2+1}\,dz - \int_{-R+2i}^{R+2i}f(z)\,dz + o(1)\\&=& 2\pi i\cdot\text{Res}\left(f(z),z=i\right)=\pi\cosh(1) \end{eqnarray*}$$
as $R\to +\infty$, hence in order to compute the given limit it is enough to compute
$$ \lim_{R\to +\infty}\int_{-R}^{+R}\frac{\cos(z)}{z^2+1}\,dz =\text{Re}\left[2\pi i\cdot \text{Res}\left(\frac{e^{iz}}{z^2+1},z=i\right)\right]=\frac{\pi}{e}$$
to get:
$$ \lim_{R\to +\infty}\int_{-R+2i}^{R+2i}f(z)\,dz = \color{red}{-\pi\sinh(1)}.$$