<s>[INST] Solve real integrals $\int_0^{2\pi} \frac{d\theta}{1+a\cos(\theta)} = \frac{2\pi}{\sqrt{1-a^2}}$ using complex variables. I am trying to 

verify that $\displaystyle\int_0^{2\pi} \frac{d\theta}{1+a\cos(\theta)} = \frac{2\pi}{\sqrt{1-a^2}}$, for $-1\lt a \lt 1$.

So far I replaced $\cos(\theta)$ with $\dfrac{z+\frac{1}{z}}{2}$ and $d\theta$ with $\dfrac{dz}{iz}$, and then simplified to get $$\frac 2 i \int_C \frac{dz}{az^2+2z+a}$$ (with $C$ being the unit circle). Then this function will have simple poles at $\frac{-1\pm\sqrt{1-a^2}}{a}$. Then I calculated $\operatorname{Res}\left(f: \dfrac{-1+\sqrt{1-a^2}} a\right) = \dfrac a {2\sqrt{1-a^2}}$ and $\operatorname{Res}\left(f: \dfrac{-1-\sqrt{1-a^2}} a \right) =  \dfrac{-a}{2\sqrt{1-a^2}}$. But then when I apply the residue theorem, clearly the sum of the two residues is zero, and then the entire integral is zero. I'm sure there must be a mistake in my calculations somewhere, but I'm not sure where. I'm thinking maybe I need to use that a is between $-1$ and $1$. Any help/corrections are appreciated!
 [/INST] By symmetry
$$ \int_{0}^{2\pi}\frac{d\theta}{1+a\cos\theta} = 2\int_{0}^{\pi}\frac{d\theta}{1-a^2\cos^2\theta} =4\int_{0}^{\pi/2}\frac{d\theta}{1-a^2\cos^2\theta}$$
and by setting $\theta=\arctan t$ the last integral turns into:
$$ 4\int_{0}^{+\infty}\frac{dt}{(1+t^2)-a^2} = 2\int_{\mathbb{R}}\frac{dt}{(1-a^2)+t^2} $$
that is:
$$ 4\pi i\,\text{Res}\left(\frac{1}{(1-a^2)+t^2},t=i\sqrt{1-a^2}\right)=4\pi i\lim_{t\to i\sqrt{1-a^2}}\frac{1}{t+i\sqrt{1-a^2}} $$
i.e. $\color{red}{\large\frac{2\pi}{\sqrt{1-a^2}}}$ as wanted.
It is always worth considering symmetry tricks, because they make our life easier both in the real and complex case.
</s>