# Can't calculate $I=\int_{-\infty }^{\infty } \frac{\cos x}{x^2+1} \, dx$ using residues

I tried to calculate the integral $$I=\int_{-\infty }^{\infty } \frac{\cos x}{x^2+1} \, dx$$ using residues and got $$I=2\pi i \text{ Res}\left(\frac{\cos x}{x^2+1},(x,i)\right)=\pi \cosh 1\approx 4.8$$ which is nonsense because the graph of $$y=\frac{\cos x}{x^2+1}$$ is between $$-\frac{1}{x^2+1}$$ and $$\frac{1}{x^2+1}$$, the area between these two curves is $$2\pi$$ and $$I\approx 4.8$$ is too much.

Mathematica gives $$I=\frac{\pi}{e}\approx 1.15573$$ which makes much more sense.

My questions are.

• Given that my use of residue is wrong, what does $$\pi \cosh 1$$ represent?
• Why residue is wrong in this example?
• What contour did you pick? Dec 23, 2020 at 13:35
• I think is better to use the function $f(z)=\frac{e^{iz}}{z^2+1}$, since for $x\in\Bbb R$, $\Re(f(x))=\frac{\cos x}{x^2+1}$. Here you have exactly the same integral calculated. (PAge 9, In Spanish). Dec 23, 2020 at 13:36
• @AryamanMaithani This one upload.wikimedia.org/wikipedia/commons/thumb/9/93/… Dec 23, 2020 at 13:39
• @Raffaele: That is what I suspected. It is better to use Tito Eliatron's function in that case. The integral (over the semi-circular arc) of the function you chose does not vanish in the limit. (In fact, using the correct function, you can actually calculate what it is, in the limit!) Dec 23, 2020 at 13:41
• @TitoEliatron Thank you so much! Could not ask more. Amusing that the integral in Spanish is female. In Italian is male :) Dec 23, 2020 at 13:44

What you need to do is to calculate the residue of $$\dfrac{e^{iz}}{z^2+1}$$ then get the real part of it, since $$\cos(z)$$ is not a bounded function on the upper complex plane but $$e^{iz}$$ is.