TITLE: Computing real integral using residues
QUESTION [6 upvotes]: 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?

REPLY [3 votes]: You said you were interested in Residues. I will Laplace Transforms (which is residues in disguise). To do so, I will employ Feynman's Trick by first introducing the following function:
\begin{equation}
F(t) = \int_{-\infty}^\infty \frac{\cos(tx)}{\left(x^2 + 4\right)^2}\:dx
\end{equation}
We observe that your integral $I = F(2)$. First we observe that the parity of the integrand is even, thus, 
\begin{equation}
F(t) = 2\int_{0}^\infty \frac{\cos(tx)}{\left(x^2 + 4\right)^2}\:dx
\end{equation}
We now proceed to take the Laplace Transform of $F(t)$. To do so, we must employ Fubini's Theorem:
\begin{align}
 \mathscr{L}_{t \rightarrow s}\left[ F(t)\right] &= 2\int_{0}^\infty \frac{\mathscr{L}_{t \rightarrow s}\left[\cos(tx)\right]}{\left(x^2 + 4\right)^2}\:dx  = 2 \int_0^\infty \frac{s}{s^2 + x^2} \cdot \frac{1}{(x^2 + 4)^2}\:dx \nonumber \\
&= 2s \int_0^\infty \frac{1}{(s^2 + x^2)(x^2 + 4)^2}\:dx \nonumber \\
&= 2s \int_0^\infty \frac{1}{(s^2 - 4)^2}\left[ \frac{s^2 - 4}{(x^2 + 4)^2} - \frac{1}{x^2 + 4} + \frac{1}{s^2 + x^2}\right]\:dx \nonumber \\
&= \frac{2s}{(s^2 - 4)^2}\left[ (s^2 - 4)\int_0^\infty \frac{1}{(x^2 + 4)^2}\:dx - \int_0^\infty \frac{1}{x^2 + 4}\:dx + \int_0^\infty\frac{1}{s^2 + x^2}\:dx \right] \nonumber \\
&=\frac{2s}{(s^2 - 4)^2} \left[ (s^2 - 4)A - B  + C\right]
\end{align}
We now resolve $A,B,C$. We start with $C$:
\begin{equation}
C = \int_0^\infty \frac{1}{s^2 + x^2}\:dx = \left[ \frac{1}{s}\arctan\left(\frac{x}{s}\right) \right]_0^\infty = \frac{1}{s}\cdot \frac{\pi}{2} = \frac{\pi}{2s}
\end{equation}
We observe that $B$ is just $C$ when $s = 2$, thus:
\begin{equation}
B = \int_0^\infty \frac{1}{2^2 + x^2}\:dx = \frac{\pi}{2\cdot 2} = \frac{\pi}{4}
\end{equation}
For $A$ we make the substitution $x = 2\tan(p)$:
\begin{align}
A &= \int_0^\frac{\pi}{2} \frac{1}{\left(4\tan^2(p) + 4\right)^2} \cdot 2\sec^2(p)\:dp = \frac{1}{8}\int_0^\frac{\pi}{2} \cos^2(x)\:dx = \frac{1}{8}\int_0^\frac{\pi}{2} \frac{\cos(2x) + 1}{2}\:dx \nonumber \\
&= \frac{1}{16}\left[ \frac{\sin(2x)}{2} + x \right]_0^\frac{\pi}{2} = \frac{1}{16} \cdot \frac{\pi}{2} = \frac{\pi}{32}
\end{align}
Thus, 
\begin{align}
\mathscr{L}_{t \rightarrow s}\left[ F(t)\right] &=\frac{2s}{(s^2 - 4)^2} \left[ (s^2 - 4)A - B  + C\right] = \frac{2s}{(s^2 - 4)^2} \left[ (s^2 - 4)\frac{\pi}{32} - \frac{\pi}{4}  + \frac{\pi}{2s}\right] \nonumber \\
&=  2 \pi \left[ \frac{1}{32}\cdot\frac{s}{s^2 - 4} - \frac{1}{4}\cdot \frac{s}{(s^2 - 4)^2}  + \frac{1}{2} \cdot \frac{1}{(s^2 - 4)^2}\right]
\end{align}
To resolve $F(t)$ we now take the inverse Laplace Transform:
\begin{align}
F(t) &= 2 \pi \left[ \frac{1}{32}\mathscr{L}^{-1}_{s \rightarrow t}\left[\frac{s}{s^2 - 4}\right] - \frac{1}{4}\mathscr{L}^{-1}_{s \rightarrow t}\left[\frac{s}{(s^2 - 4)^2}\right]  + \frac{1}{2} \mathscr{L}^{-1}_{s \rightarrow t}\left[ \frac{1}{(s^2 - 4)^2}\right]\right] \nonumber \\
&= 2 \pi \left[ \frac{1}{32}\cdot \cosh(2t) - \frac{1}{4} \cdot\frac{t\sinh(2t)}{4} + \frac{1}{2}\cdot \frac{2t\cosh(2t) - \sinh(2t)}{16}\right] \nonumber \\
&= \pi \left[ \frac{1}{16}\cdot \cosh(2t) -  \frac{t\sinh(2t)}{8} + \frac{2t\cosh(2t) - \sinh(2t)}{16}\right] \nonumber \\
&= e^{-2t}(2t + 1)\frac{\pi}{16}
\end{align}
Thus, 
\begin{equation}
F(t) = \int_{-\infty}^\infty \frac{\cos(tx)}{\left(x^2 + 4\right)^2}\:dx = e^{-2t}(2t + 1)\frac{\pi}{16}
\end{equation}
Recall that for your integral $I = F(2)$, thus, 
\begin{equation}
I = F(2) = e^{-2(2)}(2(2) + 1)\frac{\pi}{16} = 5e^{-4} \frac{\pi}{16}
\end{equation}