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...
 A: A quick and dirty way to check this.  Let 
$$f(m) = \int_{-1}^1 \frac{dx}{1+m x^2}  = \frac{2}{m} \int_0^1 \frac{dx}{1/m+x^2} = \frac{2}{\sqrt{m}}\arctan \sqrt{m}$$
$$f'(m) = -\int_{-1}^1 dx \frac{x^2}{(1+m x^2)^2}  = -m ^{-3/2} \arctan{\sqrt{m}} + \frac1{m (1+m)}$$
Your integral is thus
$$-f'(n^2) = \frac{\arctan{n}}{n^3} - \frac1{n^2 (1+n^2)} $$
A: 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.]
A: To avoid multiple complex conjugate roots, you can use the formula in Application to symbolic integration
\begin{align}
\frac{x^2}{(1+n^2x^2)^2}
  &=\frac{d}{dx}\left[\frac{Ax+B}{1+n^2x^2}\right]+\frac{Cx+D}{1+n^2x^2}\\
  &=\frac{Cn^2x^3+(D-A)n^2x^2+(C-2Bn^2)x+(D+A)}{(1+n^2x^2)^2}
\end{align}
so that
$$\left\{
\begin{align}
A&=-\frac{1}{2n^2}\\
B&=0\\
C&=0\\
D&=+\frac{1}{2n^2}
\end{align}
\right.
$$
and the integral becomes
\begin{align}
\int\frac{x^2}{(1+n^2x^2)^2}dx
  &=\frac{Ax+B}{1+n^2x^2}+\int\frac{Cx+D}{1+n^2x^2}dx\\
  &=-\frac{x}{2n^2(1+n^2x^2)}+\frac{1}{2n^2}\int\frac{1}{1+n^2x^2}dx\\
  &=-\frac{x}{2n^2(1+n^2x^2)}+\frac{1}{2n^3}\arctan(nx)+c
\end{align}
