Integrate rational function with multiple complex roots I want to integrate
$$
 \int_{-1}^1 \frac{x^2}{(1+n^2x^2)^2} dx.
$$
By WolframAlpha I know the solution is
$$
 \int_{-1}^1 \frac{x^2}{(1+n^2x^2)^2} dx = \frac{\arctan(n) - \frac{n}{n^2+1}}{n^3}.
$$
Do derive it on my own, I did a partial fraction decomposition and found
$$
 \frac{x^2}{(1+n^2x^2)^2} = \frac{\frac{1}{2n^2}}{1+n^2x^2} + \frac{\frac{1}{4n^2}}{(x-i/n)^2} + \frac{\frac{1}{4n^2}}{(x+i/n)^2}. 
$$
I checked this multiple times, but it must be wrong, because when I proceed with it I get
\begin{align*}
 \int_{-1}^1 \frac{x^2}{(1+n^2x^2)^2} dx
  & = \frac{1}{n^2} \left( \frac{1}{2} \int_{-1}^1 \frac{1}{1+n^2x^2} d x + \frac{1}{4} \int_{-1}^1 \frac{1}{(x-i/n)^2} d x + \frac{1}{4} \int_{-1}^1 \frac{1}{(x+i/n)^2} d x \right) \\
& = \frac{1}{n^2}\left( \frac{1}{2} \frac{\arctan(xn)}{n}\bigg\vert_{-1}^1 + \frac{1}{4} \left( \frac{-1}{x-i/n}\bigg\vert_{-1}^1 + \frac{-1}{x+i/n}\bigg\vert_{-1}^1 \right)\right) \\
& = \frac{1}{n^2} \left( \frac{\arctan(n)}{n} + \frac{1}{4} \left( \frac{-2}{1+1/n^2} + \frac{-2}{1+1/n^2}\right)\right) \\
& = \frac{1}{n^2} \left( \frac{\arctan(n)}{n} -\frac{1}{1+1/n^2} \right) \\
& = \frac{1}{n^2} \left( \frac{\arctan(n)}{n} - \frac{n^2}{n^2+1} \right) \\
& = \frac{\arctan(n)}{n^3} - \frac{1}{n^2+1}
\end{align*}
This result is consistent which what I found with WolframAlpha, but surely
$$
 \frac{\arctan(n)}{n^3} - \frac{1}{n^2+1} \ne \frac{\arctan(n) - \frac{n}{n^2+1}}{n^3}
$$
so what went wrong, I am sitting here since hours and do not see any fault...

You have a strange form for your partial fraction decomposition.  I would be inclined to stay in the field of real numbers and write:
$$
\frac{x^2}{(1+n^2x^2)^2} = \frac{Ax+B}{1+n^2x^2} + \frac{Cx+D}{(1+n^2x^2)^2}
$$
It turns out $B=\frac{1}{n^2}$ and $D = -\frac{1}{n^2}$, while $A=C=0$.
To integrate $\int\frac{dx}{(1+n^2x^2)^2}$, use the substitution $nx=\tan\theta$.   Then $n\,dx = \sec^2\theta\,d\theta$ and $(1+n^2x^2)^{\color{green}{2}} = \sec^4\theta$.  You get
\begin{align*}
    \int\frac{dx}{(1+n^2x^2)^2} &= \frac{1}{n}\int\frac{\sec^2\theta\,d\theta}{\sec^4\theta} \\
&= \frac{1}{n} \int\cos^2\theta\,d\theta \\
&= \frac{1}{2n} \int(1+ \cos(2\theta))\,d\theta\\
&= \frac{\theta}{2n} + \frac{1}{4n}\sin(2\theta) + C \\
&= \frac{\arctan(nx)}{2n}+\frac{1}{2n}\sin\theta \cos\theta + C \\
&= \frac{\arctan(nx)}{2n}+\frac{1}{2n}\frac{nx}{\sqrt{1+n^2x^2}}\frac{1}{\sqrt{1+n^2x^2}} + C \\
&= \frac{\arctan(nx)}{2n}+\frac{1}{2}\frac{x}{1+n^2x^2} + C \\
\end{align*}
[Green exponent of $2$ added thanks to Stefan's careful eye.]
