<s>[INST] Computing real integral using residues Let's consider the following integral
$$\int \limits_{-\infty}^{\infty} \frac{\cos2x}{(x^2+4)^2} \, dx. \tag{1}$$
I would like to compute $(1)$ using residue theory. Let's consider a complex function
$$f(z) = \frac{\cos2z}{(z^2+4)^2} = \frac{\cos2x}{(z-2i)^2(z+2i)^2}.$$
Of course $\text{Im}(-2i) < 0$ thus I am to calculate residue only in the point $z_0 = 2i$.
Noting that $z_0$ is a double pole we have
$$R = \text{res}_{z_0}f(z) = \lim_{z \to 2i} \frac{d}{dz} \bigg((z-2i)^2 \frac{\cos(2z)}{(z-2i)^2(z+2i)^2} \bigg).$$
After some calculations we get
$$R = \frac{i \big(-5 + 3 e^8 \big)}{64 e^4}.$$
That implies
$$\int \limits_{-\infty}^{\infty} \frac{\cos2x}{(x^2+4)^2} \, dx = 2 \pi i \frac{i \big(-5 + 3 e^8 \big)}{64 e^4} = -\frac{(-5 + 3 e^8) \pi}{32 e^4}.$$
According to WolframAlpha $(1)$ is equal to
$$\frac{5 \pi}{16 e^4}.$$
What am I doing wrong?
 [/INST] I want to write more details, may helps someone. Consider
$$\int_C \frac{e^{2iz}}{(z^2+4)^2} \, dz$$
where $C$ is the contour, the semicircle in upper half plane (as you have gotten I think), then the integrand has poles at $z=\pm 2i$, which it's reside at $z=2i$ is
$$\operatorname{Res}_{f}(2i) = \lim_{z\to2i} \frac{d}{dz} \bigg((z-2i)^2 \frac{e^{2iz}}{(z-2i)^2(z+2i)^2} \bigg) = \lim_{z\to2i} e^{2iz}\dfrac{2iz-6}{(z+2i)^3}=-i\dfrac{5}{32}e^{-4}$$
then
$$\int_{-R}^{R}\dfrac{\cos2z+i\sin2z}{(z^2+4)^2} \, dz+\int_\gamma \frac{e^{2iz}}{(z^2+4)^2} \, dz=2\pi i\times-i\dfrac{5}{32}e^{-4}=\dfrac{5\pi}{16}e^{-4}$$
where $\gamma$ is upper semicircle $|z|=1$. Finally take the limit $R\to\infty$ and $find the result.
</s>