Let $C_R\subset\mathbb C$ be a directed line segment that goes from $-R+2i$ to $R+2i$. I would like to evaluate $$ \lim_{R\rightarrow\infty} \int_{C_R} \frac{\cos z}{z^2 + 1}\ dz. $$ I obviously tried to do this by residue calculus. I tried expressing $\cos$ in terms of $\exp$, or experimenting with various closed curves that contains $C_R$, but in vain.
I would be grateful if you could give a clue.
Let $\gamma_R^+$ be the curve that goes from $-R+2i$ to $R+2i$ then circles counter-clockwise back above the line to $-R+2i$ and $\gamma_R^-$ be the curve that goes from $-R+2i$ to $R+2i$ then circles clockwise back below the line to $-R+2i$. Then, your limit equals $$ \lim_{R\to\infty}\left(\frac12\int_{\gamma_R^+}\frac{e^{iz}}{z^2+1}\,\mathrm{d}z +\frac12\int_{\gamma_R^-}\frac{e^{-iz}}{z^2+1}\,\mathrm{d}z\right)\tag{1} $$ $\gamma_R^+$ does not contain any singularities, so the first integral is $0$. $\gamma_R^-$ contains the singularities at $i$ and $-i$. The residue at $i$ is $-\frac{ei}{2}$ and the residue at $-i$ is $\frac{i}{2e}$. The integral over $\gamma_R^-$ is $-2\pi i$ times the sum of the residues, which is $-\pi\left(e-\frac1e\right)$. Thus, $(1)$ is $$ -\frac\pi2\left(e-\frac1e\right)\tag{2} $$