Residue Formula application Using the Residue formula, I've been trying to prove $$\int_0^{2\pi}\frac{1}{a^2\cos^2\theta+b^2\sin^2\theta}\,d\theta=\frac{2\pi}{ab},\quad\quad a,b\in\Bbb R.$$First, it seems like the formula should be wrong (unless perhaps we assume $a,b\in\Bbb R^+$) since the right-hand side can be negative, but the integrand on the left is always non-negative. Currently I'm assuming the additional requirement $a,b>0$.
With that said, to approach it, I use Euler's formulas on the trig. functions in the denominator and make a change of variables, $$z=e^{i\theta},\quad \frac{1}{iz}\,dz=d\theta.$$Now, if I have calculated correctly, the integral reduces to $$\int_{|z|=1}\frac{1}{iz}\cdot\frac{1}{\frac{a^2}{4}\left(z+z^{-1}\right)^2-\frac{b^2}{4}\left(z-z^{-1}\right)^2}\,dz.$$We can factor $z^{-2}$ from the right-side denominator to get $$\int_{|z|=1}\frac{z}{i}\cdot\frac{1}{\frac{a^2}{4}\left(z^2+1\right)^2-\frac{b^2}{4}\left(z^2-1\right)^2}\,dz.$$Since the denominator is a difference of squares, we can factor the denominator as $$\int_{|z|=1}\frac{4z}{i}\cdot\left(\frac{1}{a(z^2+1)-b(z^2-1)}\right)\cdot\left(\frac{1}{a(z^2+1)-b(z^2-1)}\right)\,\,dz. $$This is where I really started running into trouble. I tried solving when the denominator of the right term vanished and I found $$z=\pm\sqrt{\frac{b+a}{b-a}}.$$ This didn't seem right because it doesn't always have to be inside the unit circle (I don't think), so I think I might have made an error in calculation.
Is my method so far correct, or is there a far better way to calculate this integral using the residue formula? This isn't homework, just prepping for an exam. Thanks!
 A: Indeed, there is a better way! I'll give you an explanation almost straight out of Lang's $Complex$ $Analysis$.
So let's say you want to evaluate $\int_0^{2\pi} Q(\sin \theta\ \cos \theta) d\theta$, $Q$ being a rational function $Q(x,y)$, continuous on the unit circle. We know $\cos x = \frac{e^{ix} + e^{-ix}}{2}$ and $\sin x = \frac{e^{ix} - e^{-ix}}{2i}$ so if $z \in S^1$ (i.e. $z = e^{i\theta}$) we have $\cos x = \frac{z + 1/z}{2}$ and $\sin x = \frac{z - 1/z}{2i}$.  Thus we can consider the "natural" function $f(z) = Q(\frac{z + 1/z}{2}, \frac{z - 1/z}{2i})/iz$ ($iz$ being the unnatural part, but its time will come). Note that $f$ has no poles in $S^1$ because $Q$ is continuous there. Now by definition of $f$ we have that
$\int_0^{2\pi} f(e^{i\theta})ie^{i\theta}d\theta = \int_0^{2\pi} Q(\cos \theta, \sin \theta) d\theta$
where the $iz$ cancelled with the $ie^{i\theta}$. But by the residue formula we have that
$\int_0^{2\pi} f(z) dz = 2\pi i \sum \text{Residues of $f$ inside the unit circle}$
so we have
$\int_0^{2\pi} Q(\cos \theta, \sin \theta) d\theta = 2\pi i \sum \text{Residues of $f$ inside the unit circle}$
Using this method your integral should be much easier.
Edit: This is essentially what you were doing, and in fact you get the exact same integral for $f$ (the second integral you listed). The only difference is that you use the residue formula there. I just wanted to give you an easy-to-remember general method for calculating rational trigonometric integrals, since you're reviewing for a test.
A: Your methodology is fine, excellent even.  I will say that you made an error in you step of getting the difference of 2 squares; there are  unique roots when $a \ne b$:
$$z = \pm \sqrt{\frac{a \pm b}{a \mp b}}$$
A: You can use trigonometric substitution to solve this problem. 
Suppose $a<b$. Let $k=\frac{b}{a},t=\tan\frac{\theta}{2}$. Then $k>1$ and
$$ \sin\theta=\frac{2t}{t^2+1}, \cos\theta=\frac{t^2-1}{t^2+1},d\theta=\frac{2t}{t^2+1}dt $$
and hence
\begin{eqnarray*}
\int_0^{2\pi}\frac{1}{a^2\cos^2\theta+b^2\sin^2\theta}d\theta&=&\frac{2}{a^2}\int_{-\infty}^\infty\frac{t^2+1}{(t^2-1)^2+4k^2t^2}dt\\
&=&\frac{2}{a^2}\int_{-\infty}^\infty\frac{t^2+1}{t^4+2(2k^2-1)t^2+1}dt\\
&=&\frac{2}{a^2}\int_{-\infty}^\infty\frac{t^2+1}{(t^2+(2k^2-1))^2+4k^2(1-k^2)}dt\\
&=&\frac{2}{a^2}\int_{-\infty}^\infty\frac{t^2+1}{(t^2+\alpha)(t^2+\beta)}dt\\
&=&\frac{2}{a^2}\int_{-\infty}^\infty\left(\frac{A}{t^2+\alpha}+\frac{B}{t^2+\beta}\right)dt\\
&=&\frac{2}{a^2}(\frac{A\pi}{\sqrt{\alpha}}+\frac{B\pi}{\sqrt{\beta}})\\
&=&\frac{2\pi}{ab}
\end{eqnarray*}
where
$$ \alpha=(2k^2-1)+2k\sqrt{k^2-1},\beta=(2k^2-1)-2k\sqrt{k^2-1},A=\frac{\alpha-1}{\alpha-\beta}, B=\frac{1-\beta}{\alpha-\beta},$$
Suppose $a>b$. Let $k=\frac{b}{a},t=\tan\frac{\theta}{2}$. Then $k>1$ and hence
\begin{eqnarray*}
\int_0^{2\pi}\frac{1}{a^2\cos^2\theta+b^2\sin^2\theta}d\theta&=&2\int_0^{\pi}\frac{1}{a^2\cos^2\theta+b^2\sin^2\theta}d\theta\\
&=&2\int_0^{\pi}\frac{1}{a^2\frac{1+\cos2\theta}{2}+b^2\frac{1-\cos2\theta}{2}}d\theta\\
&=&4\int_0^{\pi}\frac{1}{(a^2+b^2)+(a^2-b^2)\cos2\theta}d\theta\\
&=&2\int_0^{2\pi}\frac{1}{(a^2+b^2)+(a^2-b^2)\cos\theta}d\theta\\
&=&\frac{2}{a^2-b^2}\int_0^{2\pi}\frac{1}{\alpha+\cos\theta}d\theta\\
&=&\frac{2}{a^2-b^2}\int_{-\infty}^{\infty}\frac{1}{\alpha+\frac{t^2-1}{t^2+1}}\frac{2}{t^2+1}dt\\
&=&\frac{2}{a^2-b^2}\int_{-\infty}^{\infty}\frac{2}{\alpha(t^2-1)+t^2-1}dt\\
&=&\frac{4}{a^2-b^2}\int_{-\infty}^{\infty}\frac{2}{(\alpha+1)t^2+\alpha-1}dt\\
&=&\frac{4}{(a^2-b^2)(\alpha+1)}\int_{-\infty}^{\infty}\frac{1}{t^2+\frac{\alpha-1}{\alpha+1}}dt\\
&=&\frac{4}{(a^2-b^2)(\alpha+1)}\sqrt{\frac{\alpha+1}{\alpha-1}}\pi\\
&=&\frac{2\pi}{ab}.
\end{eqnarray*}
where
$$ \alpha=\frac{a^2+b^2}{a^2-b^2}>1. $$
