Integrating $ \int^{\pi}_{0} \frac{\cos^2 x}{a^2 \cos^2 x + b^2 \sin^2 x} \ dx $ I am trying to show that
$$ \int^{\pi}_{0} \frac{\cos^2 x}{a^2 \cos^2 x + b^2 \sin^2 x} \ dx = \frac{\pi}{a(a+b)} $$ where $ a,b > 0$.
I have tried a few things, but none have worked.
For example, one approach was
$$ \int^{\pi}_{0} \frac{\cos^2 x}{a^2 \cos^2 x + b^2 \sin^2 x} \ dx = \int^{\pi}_{0} \frac{\cos^2 x}{(a^2 - b^2)\cos^2 x + b^2} \ dx$$ and then divide by $ a^2 - b^2 $ throughout. However I am not given that $ a \not= b $, so this approach didn't work.
I also tried splitting up the integral, but then was not sure how to proceed:
$$ \int^{\pi}_{0} \frac{\cos^2 x}{a^2 \cos^2 x + b^2 \sin^2 x} \ dx =  \int^{\frac{\pi}{2}}_{0} \frac{\cos^2 x}{a^2 \cos^2 x + b^2 \sin^2 x} \ dx + \int^{\pi}_{\frac{\pi}{2}} \frac{\cos^2 x}{a^2 \cos^2 x + b^2 \sin^2 x} \ dx   $$
Substituting $ x \to x + \frac{\pi}{2} $ followed by $ x \to \frac{\pi}{2} -x $ a in the second integral gives
$$ \int^{\frac{\pi}{2}}_{0} \frac{\cos^2 x}{a^2 \cos^2 x + b^2 \sin^2 x} \ dx $$ 
Hence $$ \int^{\pi}_{0} \frac{\cos^2 x}{a^2 \cos^2 x + b^2 \sin^2 x} \ dx = 2 \int^{\frac{\pi}{2}}_{0} \frac{\cos^2 x}{a^2 \cos^2 x + b^2 \sin^2 x} \ dx $$
Next I thought I could substitute $ u = a^2 \cos^2 x + b^2 \sin^2 x $ which changes my limits from $[0, \frac{\pi}{2}]$ to $[a^2, b^2]$, however I could not complete the substitution as I didn't see how to express $ du = (b^2 - a^2) \sin 2 x \ dx $ or $ \cos^2 x$ in terms of $u$.
 A: If we set $x=\arctan t$ we simply have:
$$I(a,b)=\int_{0}^{\pi}\frac{\cos^2 x}{b^2\sin^2 x+a^2\cos^2 x}\,dx = 2\int_{0}^{+\infty}\frac{dt}{(1+t^2)(a^2+b^2 t^2)}$$
that is straightforward to compute through partial fraction decomposition or through the residue theorem.
A: Suppose we seek to evaluate
$$\int_0^\pi \frac{\cos^2 x}{a^2\cos^2x + b^2\sin^2x} dx
= \frac{1}{2}
\int_0^{2\pi} \frac{\cos^2 x}{a^2\cos^2x + b^2\sin^2x} dx$$
with $a,b>0.$
Put  $z   =  \exp(ix)$  so  that   $dz  =  i\exp(ix)   dx$  and  hence
$\frac{dz}{iz} = dx$ to obtain
$$\frac{1}{2}\int_{|z|=1}
\frac{(z+1/z)^2}{a^2(z+1/z)^2-b^2(z-1/z)^2} \frac{dz}{iz}
\\ = \frac{1}{2}\int_{|z|=1}
\frac{(z^2+1)^2}{a^2(z^2+1)^2-b^2(z^2-1)^2} \frac{dz}{iz}.$$
This factors to give
$$\frac{1}{2}\int_{|z|=1}
\frac{(z^2+1)^2}{(a(z^2+1)+b(z^2-1))(a(z^2+1)-b(z^2-1)} \frac{dz}{iz}.$$
The roots of the first term are
$$\rho_{1,2} = \pm\sqrt{\frac{b-a}{a+b}}
= \pm \sqrt{1-\frac{2a}{a+b}} $$
and of the second term
$$\rho_{3,4} = \pm\sqrt{\frac{a+b}{b-a}}
= \pm \sqrt{1+\frac{2a}{b-a}}.$$
We  now treat  the  case  of $b>a$  which  gives $|\rho_{1,2}|<1$  and
$|\rho_{3,4}|>1.$ We  may therefore apply the  Cauchy Residue Theorem,
taking  into  account the  contributions  from  $\rho_{1,2}$ and  from
$z=0.$

The residues at $\rho_{1,2}$ are
$$\left.
\frac{(z^2+1)^2}
{a^2\times 2(z^2+1)2z-b^2\times 2(z^2-1)2z}
\frac{1}{iz}\right|_{z=\rho_{1,2}.}$$
This is
$$\frac{1}{4i} \left.
\frac{(z^2+1)^2}
{a^2\times (z^2+1)z^2-b^2\times (z^2-1)z^2}
\right|_{z=\rho_{1,2}}
\\ = \frac{1}{4i} \left.
\frac{(z^2+1)^2}
{a^2\times (z^2+1)^2-b^2\times (z^2-1)^2
- a^2(z^2+1) - b^2(z^2-1)}
\right|_{z=\rho_{1,2}.}$$
Considering the definition of $\rho_{1,2}$ this becomes
$$-\frac{1}{4i} \left.
\frac{(z^2+1)^2}
{a^2(z^2+1) + b^2(z^2-1)}
\right|_{z=\rho_{1,2}}$$
which yields
$$-\frac{1}{4i}
\frac{4b^2}
{a^2\times 2b(a+b) + b^2\times (-2a)(a+b)}
\\ = -\frac{1}{i}
\frac{b^2}
{2ab(a-b)(a+b)}
= -\frac{1}{2i}
\frac{b}
{a(a-b)(a+b)}.$$
The residue at $z=0$ is
$$\frac{1}{i} \frac{1}{a^2-b^2}
= \frac{1}{i} \frac{1}{(a-b)(a+b)}.$$
Collecting everything we obtain
$$\frac{1}{2}\times 2\pi i\times
\left(\frac{1}{i} \frac{1}{(a-b)(a+b)}
- 2\times \frac{1}{2i} \frac{b}{a(a-b)(a+b)}\right)
\\ = \frac{1}{2}\times 2\pi i\times
\frac{1}{i} \frac{1}{(a-b)(a+b)}
\left(1 - \frac{b}{a}\right)
\\ = \frac{1}{2}\times 2\pi i\times
\frac{1}{i} \frac{1}{(a-b)(a+b)} \frac{a-b}{a}
\\ = \frac{\pi}{a(a+b)}.$$
