I'm trying to find the value of the following expression using the residue theorem...
$$\int_{0}^{\infty} \frac{\cos(2x)}{x^2+4}dx$$ My attempt is as follows: I've separated the denominator into two fractions $$=\int_{0}^{\infty} \frac{\cos(2x)}{(x+j2)(x-j2)}dx$$ Now multiply by each fraction to get the residue at both poles and using Euler's identities...
$$\frac{\cos(2x)}{(x-j2)},\ x=-j2 =>\frac{1}{-j4}\frac{e^4+e^{-4}}{2}$$ $$\frac{\cos(2x)}{(x+j2)},\ x=j2 =>\frac{1}{j4}\frac{e^{-4}+e^{-4}}{2}$$
Add then together and multiply by $j2\pi$
$$j2\pi[\frac{1}{j4}\frac{e^{-4}+e^{-4}}{2} - \frac{1}{j4}\frac{e^4+e^{-4}}{2}]$$ $$\frac{\pi}{2}(\frac{e^{-4}-e^{4}}{2})$$ This is different from the answer I get in Wolfram Alpha which is $\frac{\pi}{4e^4}$. Can anyone spot my error or misunderstanding of how the theorem works?
Observe that $$ \int_{0}^{+\infty} \frac{\cos (2x)}{x^2+4}\,d x=\frac1{2}\int_{-\infty }^{+\infty }\frac{\cos (2x)}{x^2+4}\,d x=\frac1{2}\operatorname{Re}\left[\int_{-\infty }^{+\infty }\frac{e^{i2x}}{x^2+4}\,d x\right] $$ Now observe that $|e^{iz}|=e^{\operatorname{Re}(iz)}=e^{-\operatorname{Im}(z)}$, so $\lim_{\operatorname{Im}(z)\to +\infty }|e^{iz}|=0$, and use a contour $\gamma_R :=\alpha _R\oplus \beta_R$ defined by $$ \alpha _R:[-R,R]\to \mathbb{C},\, t\mapsto t\\ \beta _R:[0,\pi]\to \mathbb{C},\, t\mapsto Re^{it} $$
Then you find that $$ \begin{align*} \int_{0}^{+\infty} \frac{\cos (2x)}{x^2+4}\,d x&=\frac1{2}\operatorname{Re}\left[\lim_{R\to +\infty }\int_{\gamma _R}\frac{e^{i2z}}{z^2+4}\,d z\right]\\&=\frac1{2}\operatorname{Re}\left[ 2\pi i\cdot \operatorname{res}\left(\frac{e^{i2z}}{z^2+4}, z=2i\right)\right]\\ &=\frac{\pi}{4e^{4}} \end{align*} $$
as $\lim_{R\to +\infty }\int_{\beta _R}\frac{e^{iz}}{z^2+4}\,d z=0$.