The question:\,
Calculate $$\int_{-\infty}^\infty{x^2\,dx\over (1+x^2)^2}.$$
Book's final solution: $\dfrac\pi 2$.
My mistaken solution: I don't see where is my mistake because my final solution is $-\dfrac{\pi i}2$:
$$\begin{align} \text{A}:\int_{-\infty}^\infty {x^2\over (1+x^2)^2}dx &= 2\int_{0}^\infty {x^2\over (1+x^2)^2}dx \quad\text{as the function is even}\\&= -2\left(\text{Res}\left({z^2\over (1+z^2)^2}\cdot \ln(z) ,i\right)+\text{Res}\left({z^2\over (1+z^2)^2}\cdot \ln(z) ,-i\right)\right)\end{align} $$ Calculate the residues: Since $\pm i$ are poles of order $2$, then $$\begin{align}\text{B}:\text{Res}\left({z^2\ln z\over (1+z^2)^2} ,i\right)&={(2z\ln z+z^2\cdot z^{-1})(z+i)^2-z^2\ln z\cdot 2(z+i)\over (z+i)^4} \\&= \frac{(2i\ln i+i)(-4)+\ln i\cdot 4i }{16} \\ &= {1\over 16} (-8i\ln i -4i+4i\ln i)={-1\over 4}i(\ln i+1)\end{align} $$ whereas $$\begin{align}\text{C}:\text{Res}\left({z^2\ln z\over (1+z^2)^2} ,-i\right)&={(2z\ln z+z^2\cdot z^{-1})(z-i)^2-z^2\ln z\cdot 2(z-i)\over (z-i)^4} \\ &=\frac{(-2i\ln(- i)-i)(-4)+\ln (-i)\cdot (-4i)}{16} \\ &= {1\over 16} (8i\ln (-i) +4i-4i\ln(- i))={1\over 4}i(\ln (-i)+1)\end{align} $$ Combining $\text A$, $\text B$ and $\text C$, we get $$ \int_{-\infty}^\infty {x^2\over (1+x^2)^2}\,dx=-2\left({i\over 4}(\ln(-i)+1)-{i\over 4}(\ln i+1)\right)={-i\over 2}\left({3\pi\over 2}-{\pi\over 2}\right)={-\pi i \over 2} $$ Where is my mistake? Thanks in advance!
That $\ln z$ makes no sense. That integral is equal to $2\pi i$ times the sum of the residues at the singularities of $\frac{z^2}{(1+z^2)^2}$ in the upper half-plane. There is actually only one such singularity: at $i$. So\begin{align}\int_{-\infty}^\infty\frac{x^2}{(1+x^2)^2}\,\mathrm dx&=2\pi i\operatorname{res}_{z=i}\left(\frac{z^2}{(1+z^2)^2}\right)\\&=2\pi i\times\left(-\frac i4\right)\\&=\frac\pi2.\end{align}