integrate $dx/(a^2 \cos^2x+b^2 \sin^2x)^2$ Integrate $\dfrac{dx}{(a^2 \cos^2x+b^2 \sin^2x)^2}$.
I can go up to the residue formula like in this example here
but then I just can't end up with the result for when $n=2$. I keep messing up my math. Can someone please show me how to get to the answer when $n=2$? I think I've spent 3+ hours trying to get to it and no luck unfortunately. Thank you!

By setting $x=\arctan t$ we have:
$$I=\int\frac{dx}{(a^2\sin^2 x+b^2\cos^2 x)^2}=\int\frac{1+t^2}{(a^2 t^2+b^2)^2}\,dt$$
and by setting $t=u\frac{b}{a}$ we get:
$$ I = \frac{1}{ab^3}\int\frac{1+\frac{b}{a} u^2}{(1+u^2)^2}\,du $$
so it is enough to check that:
$$\int \frac{du}{(1+u^2)^2} = \frac{1}{2}\left(\frac{u}{1+u^2}+\arctan u\right),\quad \int \frac{u^2\, du}{(1+u^2)^2} = \frac{1}{2}\left(\arctan u-\frac{u}{1+u^2}\right).$$
