Originally Posted by brenorocha
$
\int_0^\infty \frac{\cos x}{x^2+a^2}\,dx
$
Let $a>0.$

Define $x=au,$ the integral becomes to $\frac{1}
{a}\int_0^\infty {\frac{{\cos au}}
{{u^2 + 1}}\,du} .$

Let $f(a) = \int_0^\infty {\frac{{\cos au}}
{{u^2 + 1}}\,du} \implies f'(a) = - \int_0^\infty {\frac{{u\sin au}}
{{u^2 + 1}}\,du} .$

Now

$\int_0^\infty {e^{ - \varphi u} \cos \varphi \,d\varphi } = \text{Re} \int_0^\infty {e^{ - (u - i)\varphi } \,d\varphi } = \text{Re} \,\frac{1}
{{u - i}} = \frac{u}
{{u^2 + 1}}.$

So

$\int_0^\infty {\frac{{u\sin au}}
{{u^2 + 1}}\,du} = \int_0^\infty {\int_0^\infty {e^{ - \varphi u} \sin (au)\cos \varphi \,d\varphi } \,du} .$

Reverse integration order, so we have to find

$\int_0^\infty {e^{ - \varphi u} \sin (au)\,du} = \text{Im} \int_0^\infty {e^{ - (\varphi - ai)u} \,du} = \text{Im} \,\frac{1}
{{\varphi - ai}} = \frac{a}
{{\varphi ^2 + a^2 }}.$

From here $\int_0^\infty {\frac{{u\sin au}}
{{u^2 + 1}}\,du} =\int_0^\infty {\frac{{a\cos \varphi }}
{{\varphi ^2 + a^2 }}\,d\varphi } .$

One more substitution defined by $\varphi=a\tau,$

$\int_0^\infty {\frac{{a\cos \varphi }}
{{\varphi ^2 + a^2 }}\,d\varphi } = \int_0^\infty {\frac{{\cos a\tau }}
{{\tau ^2 + 1}}\,d\tau } = f(a).$

Then we have the following differential equation $f'(a)=-f(a),$ which is separable and easy to solve, so from here $f(a)=ke^{-a},$ where $k$ is a constant.

From the initial condition $f(0)=\frac\pi2,$ we have $k=\frac\pi2\implies f(a)=\frac{\pi e^{-a}}2.$

Since $f(a)=f(-a)\implies f(a)=\frac{\pi e^{-|a|}}2.$

And finally $\int_0^\infty \frac{\cos x}{x^2+a^2}\,dx=\frac{\pi e^{-|a|}}{2a}\,\blacksquare$