Integration of $\int_0^\infty\frac{1-\cos x}{x^2(x^2+1)}\,dx$ by means of complex analysis

$$\int_0^\infty\frac{1-\cos x}{x^2(x^2+1)}\,dx$$

Since

$$\frac{1}{{{x^2}({x^2} + 1)}} = \frac{1}{{{x^2}}} - \frac{1}{{{x^2} + 1}}$$

You have

$$\int_0^\infty {\frac{{1 - \cos x}}{{{x^2}}}} {\mkern 1mu} - \int_0^\infty {\frac{{1 - \cos x}}{{1 + {x^2}}}} dx$$

Now

$$\int_0^\infty {\frac{{1 - \cos x}}{{{x^2}}}} {\mkern 1mu} =- \left. {\frac{{1 - \cos x}}{x}} \right|_0^\infty + \int_0^\infty {\frac{{\sin x}}{x}} {\mkern 1mu} = \int_0^\infty {\frac{{\sin x}}{x}} = \frac{\pi }{2}$$

So maybe now it is easier to tackle $$\int_0^\infty {\frac{{1 - \cos x}}{{1 + {x^2}}}} dx$$ which gives

$$\int_0^\infty {\frac{{1 - \cos x}}{{1 + {x^2}}}} dx = \int_0^\infty {\frac{{dx}}{{1 + {x^2}}}} - \int_0^\infty {\frac{{\cos x}}{{1 + {x^2}}}dx} = \frac{\pi }{2} - \int_0^\infty {\frac{{\cos x}}{{1 + {x^2}}}dx} $$

and thus

$$\int_0^\infty {\frac{{1 - \cos x}}{{{x^2}({x^2} + 1)}}} {\mkern 1mu} dx = \int_0^\infty {\frac{{\cos x}}{{1 + {x^2}}}dx} $$

EDIT

Since the last solution is not very satisfactory, as it has been discussed, I'll supply this solution:

Define

$$F\left( \varphi \right) = \int\limits_0^{ + \infty } {\frac{{\cos \varphi x}}{{1 + {x^2}}}dx} $$

Clearly the integral is absolutely convergent.

Thus, use the Laplace Transform, to obtain:

$$L\left( s \right) = \int\limits_0^{ + \infty } {\frac{s}{{{x^2} + {s^2}}}\frac{1}{{1 + {x^2}}}dx} $$

We evaluate this integral:

$$\frac{s}{{{x^2} + {s^2}}}\frac{1}{{1 + {x^2}}} = \frac{s}{{1 - {s^2}}}\left( {\frac{1}{{1 + {x^2}}} - \frac{1}{{{s^2} + {x^2}}}} \right)$$

$$\eqalign{ & L\left( s \right) = \frac{s}{{1 - {s^2}}}\int\limits_0^{ + \infty } {\left( {\frac{1}{{1 + {x^2}}} - \frac{1}{{{s^2} + {x^2}}}} \right)dx} \cr & L\left( s \right) = \frac{s}{{1 - {s^2}}}\left( {\frac{\pi }{2} - \int\limits_0^{ + \infty } {\frac{1}{{{s^2} + {x^2}}}dx} } \right) \cr & L\left( s \right) = \frac{s}{{1 - {s^2}}}\left( {\frac{\pi }{2} - \frac{1}{s}\frac{\pi }{2}} \right) \cr & L\left( s \right) = \frac{\pi }{2}\frac{s}{{1 - {s^2}}}\frac{{s - 1}}{s} = \frac{\pi }{2}\frac{1}{{1 + s}} \cr} $$

Taking the inverse transform, we arrive at

$$F\left( \varphi \right) = \frac{\pi }{2}{e^{ - \varphi }}$$

This is clearly for $\varphi >0$, thus the evenness of the function forces

$$F\left( \varphi \right) = \frac{\pi }{2}{e^{ - |\varphi| }}$$

and the result follows:

$$F\left( 1 \right) = \int\limits_0^\infty {\frac{{\cos x}}{{1 + {x^2}}}dx} = \frac{\pi }{{2e}}$$



Since the integrand is even, we get $$ \begin{align} \int_0^\infty\frac{1-\cos(x)}{x^2(x^2+1)}\,\mathrm{d}x &=\frac12\int_{-\infty}^\infty\frac{1-\cos(z)}{z^2(z^2+1)}\,\mathrm{d}z\tag{1} \end{align} $$ Since $\lim\limits_{z\to0}\frac{1-\cos(z)}{z^2}=\frac12$, the singularity of the integrand near $z=0$ is removable. Therefore, since the integrand vanishes for $z$ within $\frac12$ of the real axis as $|z|\to\infty$ and there are no singularities within $\frac12$ of the real axis, the integral in $(1)$ does not change when shifting the path of integration from $z=t$ to $z=t-\frac{i}{2}$.

Now we can break up the integral as $$ \frac14\int_{\gamma^+}\frac{1-e^{iz}}{z^2(z^2+1)}\mathrm{d}z +\frac14\int_{\gamma^-}\frac{1-e^{-iz}}{z^2(z^2+1)}\mathrm{d}z\tag{2} $$ where $\gamma^+$ and $\gamma^-$ are as depicted below:

$\hspace{4.6cm}$path of integration

$\gamma^+$ circles two singularities ($z=0$ and $z=i$) clockwise, and $\gamma^-$ circles one singularity ($z=-i$) counter-clockwise.

All of the singularities are simple, so to get the residue at $z=z_0$, we just need to multiply by $z-z_0$ and taking $\displaystyle\lim_{z\to z_0}$

At $z=0$ the residue of $\displaystyle\frac{1-e^{iz}}{z^2(z^2+1)}$ is $-i$

At $z=i$ the residue of $\displaystyle\frac{1-e^{iz}}{z^2(z^2+1)}$ is $\displaystyle\frac{1-e^{-1}}{-2i}$

At $z=-i$ the residue of $\displaystyle\frac{1-e^{-iz}}{z^2(z^2+1)}$ is $\displaystyle\frac{1-e^{-1}}{2i}$

Putting these together with $(2)$ yields $$ \begin{align} \frac12\int_{-\infty}^\infty\frac{1-\cos(z)}{z^2(z^2+1)}\,\mathrm{d}z &=\frac{2\pi i}{4}\left(-i+\frac{1-e^{-1}}{-2i}\right)-\frac{2\pi i}{4}\left(\frac{1-e^{-1}}{2i}\right)\\ &=\frac{\pi}{2}\left(1-\frac{1-e^{-1}}{2}-\frac{1-e^{-1}}{2}\right)\\ &=\frac{\pi}{2e} \end{align} $$


An easy way:

Consider $$I(a)=\int_0^\infty\frac{1-\cos ax}{x^2(x^2+1)}\,dx ;a\geqslant 0$$ Next:

$$\frac{dI}{da}= \int_0^\infty\frac{\sin ax}{x}\frac{dx}{x^2+1} $$

$$\frac{d^2I}{da^2}=\int_0^\infty\frac{\cos ax}{x^2+1}\,dx=\frac{\pi e^{-a}}{2} $$

Remark: The last result is well known in this site

Thus

$$\frac{dI}{da}=-\frac{\pi e^{-a}}{2}+\frac{\pi}{2} $$ because of $\frac{dI(0)}{da}=0$

$$I(a)= \frac{\pi e^{-a}}{2}+\frac{\pi a}{2}-\frac{\pi}{2}$$ because of $I(0)=0$

Finally, original integral:

$$I=I(1)=\frac{\pi e^{-1}}{2}$$