Clarification of Contour Integration

85 Views Asked by At

I apologise if this seems like an elementary and silly question, but I am confused about the integral $$I=\int^{\infty}_{-\infty}\frac{\cos{x}}{1+x^2}dx=\frac{\pi}{e}$$ If I consider a semicircular contour with infinite radius in the upper half on the plane, I can write $$I=\Re\oint_C \frac{e^{iz}}{1+z^2}dz=\Re\left[2\pi i\lim_{z \to i}\frac{e^{iz}}{z+i}\right]=\frac{\pi}{e}$$ since the integral over the arc vanishes as the radius approaches infinity. However, I get an incorrect result if I instead use the integral $$I=\oint_C\frac{\cos{z}}{1+z^2}dz=\pi i\lim_{z \to i}\frac{e^{iz}+e^{-iz}}{z+i}=\frac{\pi}{2}(e+e^{-1})\neq \frac{\pi}{e}$$ May I know where I have made a mistake? Why are we not allowed to use (or are we?) $\cos{z}$ directly in the complex integrand but have to use $e^{iz}$ instead and extract the real part? And why is it that the 2 answers turn out to be different? Help offered to clarify my doubts will be appreciated. Thank you.