Complex Analysis integral of $\int_0^\infty \frac{\sin(x)}{x(1+x^2)^2}dx$ The problem is to calculate
$$\int_0^\infty \frac{\sin(x)}{x(1+x^2)^2}dx$$
According to Wolfram Alpha, the answer is $\frac{(2e-3)\pi}{4e}=\frac{\pi}{2}-\frac{3\pi}{4e}$, which strongly suggests an answer based on the residue theorem. The residue of the function at $i$ is $\frac{3e^{-1}-e}8 i$; multiplying by $2\pi i$, that is $-\frac{3\pi}{4e}+\frac{e\pi}4$. 
So this indicates a method of finding some contour around the point $i$ and showing that its integral approaches $\frac{e\pi}{4}-\frac{\pi}2$ as it expands (some radius $R\to \infty$).  However, I do not seem to be able to find an easy contour to integrate on. 
I've tried the obvious ones (images):


*

*Semicircular contour

*Rectangular contour
But stuff gets really weird thanks to the $\sin(x)$ and there seems to be no easy way to simplify the integrals. Any ideas?
 A: You could do it without residues. 
Write
$$\frac 1 {x(x^2+1)}=\frac 1 x+\frac{i}{4 (x-i)^2}-\frac{1}{2(x-i)}-\frac{i}{4 (x+i)^2}-\frac{1}{2 (x+ i)}$$ and you face standard integrals with obvious changes of variable.
Once integrated, the value at $\infty$ is $-\frac{\left(3-4 e+e^2\right) \pi }{8 e}$ and, at $0$, it is $-\frac{\left(e^2-3\right) \pi }{8 e}$. Then the result.
A: Define a function $ f :\mathbb{C}\rightarrow\mathbb{C} $, and a contour $ C_{R} $ for $ R\geq 1 $, as follows :
Integrating $ f $ on $ C_{R} $ gives : $$ \oint_{C_{R}}{f\left(z\right)\mathrm{d}z}=2\pi\mathrm{i}\,\mathrm{Res}\left(f,\mathrm{i}\right) $$
Since \begin{aligned} \oint_{C_{R}}{f\left(z\right)\mathrm{d}z}&=\int_{\Gamma_{R}}{f\left(z\right)\mathrm{d}z}+\int_{-R}^{-\frac{1}{R}}{f\left(x\right)\mathrm{d}x}+\int_{\Delta_{R}}{f\left(z\right)\mathrm{d}z}+\int_{\frac{1}{R}}^{R}{f\left(x\right)\mathrm{d}x}\\ &=2\int_{\frac{1}{R}}^{R}{f\left(x\right)\mathrm{d}x}+\int_{\Gamma_{R}}{f\left(z\right)\mathrm{d}z}+\int_{\Delta_{R}}{f\left(z\right)\mathrm{d}z} \end{aligned}
And $ \left|\int_{\Gamma_{R}}{f\left(z\right)\mathrm{d}z}\right|\leq\int_{\Gamma_{R}}{\left|f\left(z\right)\right|\left|\mathrm{d}z\right|}\leq\int_{C_{R}}{\frac{\left|\mathrm{d}z\right|}{\left|\left|z\right|^{2}-1\right|^{2}}}=\frac{1}{\left(R^{2}-1\right)^{2}}\int\limits_{0}^{\pi}{R\,\mathrm{d}\theta}=\frac{\pi R}{\left(R^{2}-1\right)^{2}}\underset{R\to +\infty}{\longrightarrow}0 $, and $ \int_{\Delta_{R}}{f\left(z\right)\mathrm{d}z}\underset{R\to +\infty}{\longrightarrow}0 $, we get : $$ 2\pi\mathrm{i}\,\mathrm{Res}\left(f,\mathrm{i}\right)+\pi\mathrm{i}\,\mathrm{Res}\left(f,0\right)=\lim_{R\to +\infty}{\oint_{C_{R}}{f\left(z\right)\mathrm{d}z}}=2\int_{0}^{+\infty}{f\left(x\right)\mathrm{d}x} $$
Calculating the residues : $$ \mathrm{Res}\left(f,\mathrm{i}\right)=\lim_{z\to\mathrm{i}}{\frac{\mathrm{d}}{\mathrm{d} z}\left(z-\mathrm{i}\right)^{2}f\left(z\right)}=\lim_{z\to\mathrm{i}}{\frac{\mathrm{i}\,\mathrm{e}^{\mathrm{i}z}\left(z^{2}+4\,\mathrm{i}z-1\right)}{z^{2}\left(z+\mathrm{i}\right)^{3}}}=-\frac{3}{4\,\mathrm{e}} $$
$$ \mathrm{Res}\left(f,0\right)=\lim_{z\to 0}{\frac{\mathrm{e}^{\mathrm{i}z}}{\left(z^{2}+1\right)^{2}}}=1 $$
Thus, $$ \int_{0}^{+\infty}{f\left(x\right)\mathrm{d}x}=\mathrm{i}\left(\frac{\pi}{2}-\frac{3\pi}{4\,\mathrm{e}}\right) $$
Hence, $$ \int_{0}^{+\infty}{\frac{\sin{x}}{x\left(x^{2}+1\right)^{2}}\,\mathrm{d}x}=\frac{\pi}{2}-\frac{3\pi}{4\,\mathrm{e}} $$
A: The integrand is even, so writing it as
$$ \int_0^\infty \frac{\sin(x)}{x(1+x^2)^2} \, {\rm d}x = \frac{1}{2} \int_{-\infty}^\infty \frac{\Im\left(e^{ix}\right)}{x(1+x^2)^2} \, {\rm d}x \, .$$
The imaginary part can be pulled infront of the integral when $x$ is not complex valued (which would not be the case for a complex contour), but only real. On the other hand, using complex analysis requires the contour to not be discontinuous, but it must avoid $x=0$. Therefore the integral is written as
$$\Im \left(\int_{-\infty}^\infty \frac{e^{ix}}{2x(1+x^2)^2} \, {\rm d}x + \int_{|x|=\epsilon} \frac{e^{ix}}{2x(1+x^2)^2} \, {\rm d}x \right)$$
where the first integral is now a complex contour integral encircling the singularity at $0$ clockwise at radius $\epsilon$, while the second integral is counter-clockwise to compensate for this complex valued $\epsilon$-contour. The total contour is missing that $\epsilon$-circle and is known as the principal value. Eventually $\epsilon$ goes to $0$. The first integral contour can now be closed in an arc in the upper half-plane and it is trivial to see in this case that this arc - $\lim_{R\rightarrow \infty} x=R e^{it}$ with $0<t<\pi$ - vanishes. As a result, the residue theorem can be applied and hence
$$=\Im \left(\frac{1}{2} \, \left\{ 2\pi i  \, {\rm Res}_{x=i} + i\pi {\rm Res}_{x=0} \right\} \frac{e^{ix}}{x(1+x^2)^2} \right) \\
= \Im \left( i\pi \frac{{\rm d}}{{\rm d}x} \frac{e^{ix}}{x(x+i)^2} \Bigg|_{x=i} + \frac{i\pi}{2} \right) = \Im \left( \frac{-3\pi i}{4e} + \frac{i\pi}{2} \right) = -\frac{3\pi }{4e} + \frac{\pi}{2} \, .$$
