Evaluating $\int_0^{\pi/2} \frac{a}{a^2+\cos^2 \theta} \, d\theta$ I want to evaluate 
$$
\int_0^{\pi/2} \frac{a}{a^2+\cos^2 \theta} \, d\theta
$$
and here is what Wolfram alpha gave me:
$$
\int_0^{\pi/2} \frac{a}{a^2+\cos^2 \theta} \, d\theta=\frac{\tan^{-1} \left(\frac{a \tan x}{\sqrt{a^2+1}}\right)}{\sqrt{1+a^2}}
$$
Seeing the answer, I substituted $\cos \theta = \tan x$ hoping something good would happen, but in the end it didn't lead anywhere, assuming I didn't make any mistake. But after that I'm knid of hopelessly lost.
What's the magic trick here?
 A: $$\int_0^{\pi/2} \frac{a}{a^2+\cos^2 \theta} d\theta=\int_0^{\pi/2} \frac{a\sec^2 \theta}{a^2\sec^2 \theta + 1} d\theta$$
$$=\int_0^{\pi/2} \frac{a\sec^2 \theta}{a^2(1 + \tan^2 \theta) + 1} d\theta=\int_0^{\pi/2} \frac{a\sec^2 \theta}{a^2 + 1 + a^2 \tan^2 \theta} d\theta$$
Put $a\tan \theta = x$, $ a \sec^2 \theta d\theta = dx$,
$$=\int_0^{\infty} \frac{1}{a^2 + 1 + x^2} dx =\frac{1}{\sqrt{a^2 + 1}}\arctan \frac{x}{\sqrt{a^2 + 1}} \biggl|_0^{\infty} =\frac{\pi}{2\sqrt{a^2 + 1}}$$
A: Start using $\cos(2\theta)=2\cos ^2(\theta)-1$; so $$I=\int \frac{a}{a^2+\cos^2 (\theta)} \, d\theta=\int \frac{2a}{2a^2+1+\cos(2 \theta)} \, d\theta$$ Now, use the tangent half-angle substitution $\tan(\theta)=t$. So $$I=\int\frac{2 a}{a^2 \left(t^2+1\right)+1}\,dt=\int\frac{2 a}{a^2t^2+(a^2 +1)}\,dt=\frac2a\int\frac{dt}{t^2+\frac{a^2+1}{a^2}}$$ Now, $t=\sqrt{\frac{a^2+1}{a^2}}x$.
I am sure that you can take from here.
A: Notice that: $$ \frac{a}{a^2 + cos^2\theta} = \frac{1}{2}(\frac{1}{a-icos\theta}+\frac{1}{a+icos\theta})$$
So it is enough to integrate on each of these summands. From here you can finish the calculation quite easily with the "Tangent half-angle substitution", i.e, $u = tan\frac{\theta}{2}$.
A: For the sake of completeness I present another common technique.
Suppose we are trying to evaluate
$$\int_0^{\pi/2} \frac{a}{a^2+\cos^2\theta} \; d\theta
= \frac{1}{4}
\int_0^{2\pi} \frac{a}{a^2+\cos^2\theta} \; d\theta.$$
Introduce $z=\exp(i\theta)$ so that $dz=iz\;d\theta$
to get
$$\frac{1}{4} \int_{|z|=1}
\frac{a}{a^2+(z+1/z)^2/4} \frac{1}{iz} \; dz
\\ = \frac{1}{4} \int_{|z|=1}
\frac{az^2}{z^2a^2+(z^2+1)^2/4} \frac{1}{iz} \; dz
\\ = \frac{a}{i} \int_{|z|=1}
\frac{z}{4z^2a^2+(z^2+1)^2} \; dz
\\ = \frac{a}{i} \int_{|z|=1}
\frac{z}{z^4+(4a^2+2)z^2+1} \; dz.$$
Call the function $f(z).$ The poles are at
$$\pm \sqrt{-2a^2-1 \pm 2a \sqrt{a^2+1}}$$
which is
$$\pm \sqrt{-2a^2-1 \pm 2a^2 \sqrt{1+1/a^2}}$$
When $a>1$ we have
$$\sqrt{1+1/a^2} = 1 + \frac{1}{2} 1/a^2 - \frac{1}{8} 1/a^4
+ \frac{1}{16} 1/a^6 + \cdots$$
Therefore
$$\rho_{1,2} = \pm \sqrt{-2a^2-1 + 2a^2 \sqrt{1+1/a^2}}
= \pm \sqrt{-\frac{1}{8} 1/a^4 + \frac{1}{16} 1/a^6 + \cdots}$$
so that these two poles are inside the unit circle.
On the other hand,
$$\rho_{3,4} = \pm \sqrt{-2a^2-1 - 2a^2 \sqrt{1+1/a^2}}
= \pm \sqrt{-4a^2 - 2  + \cdots}$$
so that these two poles are outside the unit circle.

It follows that the integral is given by
$$\frac{a}{i} \times
2\pi i \times
(\mathrm{Res}_{z=\rho_1} f(z) + \mathrm{Res}_{z=\rho_2} f(z))$$
or
$$2a\pi \times
(\mathrm{Res}_{z=\rho_1} f(z) + \mathrm{Res}_{z=\rho_2} f(z)).$$
These poles are simple so we get
$$\mathrm{Res}_{z=\rho_{1,2}} f(z)
=\rho_{1,2} \frac{1}{4\rho_{1,2}^3+2(4a^2+2)\rho_{1,2}}
=\frac{1}{4\rho_{1,2}^2+2(4a^2+2)}.$$
This is
$$\frac{1}{4(-2a^2-1)+ 8 a^2\sqrt{1+1/a^2} + 2(4a^2+2)}$$
or
$$\frac{1}{8 a^2\sqrt{1+1/a^2}}
= \frac{1}{8a \sqrt{a^2+1}}.$$
This finally yields for the integral 
$$2a\pi \times 2 \times \frac{1}{8a \sqrt{a^2+1}}
= \frac{\pi}{2\sqrt{a^2+1}}.$$
A: $$\small\int_0^{\pi/2} \frac{a}{a^2+\cos^2 \theta} {\rm d}\theta\stackrel{x=\tan\theta}=\int_0^{\infty} \frac{1}{1+a^2+(ax)^2} {\rm d}(ax)=\frac1{\sqrt{1+a^2}}\arctan\left(\frac{ax}{\sqrt{1+a^2}}\right)\Bigg|_{0}^{\infty}=\frac{\pi}{2\sqrt{1+a^2}}$$
