Compute the following integral using residues:
$$\int_0^{\infty}\frac{\cos x}{x^2+a^2} d x $$
$\int_0^{\infty}\frac{\cos x}{x^2+a^2} dx =\frac{1}{2}\int_{-\infty}^{\infty}\frac{\cos x}{x^2+a^2} dx =\frac{1}{4}\int_{- \infty}^{\infty}\frac{e^{ix}+e^{-ix}}{x^2+a^2} dx$.
After the substitutions $z=e^{ix}$ and $\cos(x)=\frac{1}{2}(z+\frac{1}{z})$ I get:
$\frac{1}{4}\int_{-\infty}^{\infty}\frac{e^{ix}+e^{-ix}}{x^2+a^2} dx =\frac{1}{4}\int_{-\infty}^{\infty}\frac{z+\frac{1}{z}}{e^{2iz}+a^2}\times{dz}{ie^iz}=\int_{-\infty}^{\infty}\frac{z^2+1}{z(2ie^{3iz}+2a^2ie^{iz})}dz$
In the expression $\frac{z^2+1}{z(2ie^{3iz}+2a^2ie^{iz})}$ I detected only one residue at 0, which is a simple pole. However my computation is giving me the result $\lim_{z\to 0}\frac{z^2+1}{z(2ie^{3iz}+2a^2ie^{iz})}=\frac{1}{2i+2a^2 i}$ which is wrong according with the solution.
Questions:
What am I doing wrong? How should I compute this integral?
Thanks in advance!