For $a>0$, $\displaystyle\int_{\arctan a}^{\frac{\pi}{2}}\int_{0}^{a\csc\theta}\frac{r}{(1+r^2)^2}\,dr\,d\theta=?$ I found an answer, $\displaystyle\int_{\arctan a}^{\frac{\pi}{2}}\int_{0}^{a\csc\theta}\frac{r}{(1+r^2)^2}\,dr\,d\theta=\frac{a}{2\sqrt{a^2+1}}\arctan\left(\frac{1}{\sqrt{a^2+1}}\right)$ for $a>0$.
But I am not sure how to get the result.
First of all, $\displaystyle\int_{0}^{a\csc\theta}\frac{r}{(1+r^2)^2}\,dr=-\frac{1}{2}\left(\frac{1}{1+a^2\csc^2\theta}-1\right)$ and using an integral calculator, $\displaystyle\int-\frac{1}{2}\left(\frac{1}{1+a^2\csc^2\theta}-1\right)\,d\theta=\frac{a}{2\sqrt{a^2+1}}\arctan\left(\frac{\sqrt{a^2+1}\tan \theta}{a}\right)+C$. But I can't evaluate $\tan \theta$ at $\theta=\frac{\pi}{2}$. How can I get to the answer above?
 A: So, your second integral is
$$\frac{1}{2}\int_{\tan^{-1}a}^{\frac{\pi}{2}}\frac{a^2 \csc^2 \theta}{1 + a^2\csc^2\theta}d\theta$$
Multiplying the numerator and denominator by $\sin^2\theta$, you get
$$\frac{1}{2}\int_{\tan^{-1}a}^{\frac{\pi}{2}}\frac{a^2}{\sin^2\theta + a^2}d\theta$$
The next step is very generic for solving such integrals.
Hint: Divide both numerator and denominator by $\cos^2 \theta$. Should be doable after this. I will write the complete solution anyway, but you can skip from here and try solving on your own.
$$\frac{1}{2}\int_{\tan^{-1}a}^{\frac{\pi}{2}}\frac{a^2\sec^2
\theta}{\tan^2\theta + a^2\sec^2\theta}d\theta = \frac{1}{2}\int_{\tan^{-1}a}^{\frac{\pi}{2}}\frac{a^2\sec^2
\theta}{(a^2+1)\tan^2\theta + a^2}d\theta$$
Now, let $\tan \theta = x$, you get
$$\frac{1}{2}\int_a^\infty \frac{a^2}{(a^2+1)x^2+a^2}dx = \frac{a}{2\sqrt{a^2+1}} \left[\tan^{-1}\frac{\sqrt{a^2+1}}{a}x\right]_a^\infty$$
This gives us
$$\frac{1}{2}\int_{\tan^{-1}a}^{\frac{\pi}{2}}\frac{a^2 \csc^2 \theta}{1 + a^2\csc^2\theta}d\theta = \frac{a}{2\sqrt{a^2+1}}\left[\frac{\pi}{2} - \tan^{-1}\sqrt{a^2+1}\right] = \frac{a}{2\sqrt{a^2+1}} \tan^{-1}\frac{1}{\sqrt{a^2+1}}$$
A: HINTS:
Note that we have
$$\lim_{x\to \pi/2^-}\tan(x)=\infty$$
and
$$\lim_{x\to \infty}\arctan(x)=\pi/2$$
Finally, use $\pi/2 -\arctan(x)=\arctan(1/x)$ for $x>0$.
