calculate $\int_{0}^{\pi} \frac{dx}{a+\sin^2(x)} $using complex analysis where $a>1$ calculate
$$\int_{0}^{\pi} \dfrac{dx}{a+\sin^2(x)}$$
I tried to use the regular $z=e^{ix}$ in $|z|=1$ contour. ($2\sin(x) = z-\frac1z)$, but it turned out not to work well because $\sin(x)$ in denominator.  could not found a good variables change either.
 A: We can facilitate the complex plane analysis by making use of the identity
$$\sin^2x=\frac{1-\cos 2x}{2}$$
Then, we have 
$$\begin{align}
I(a)&=\int_0^{\pi}\frac{1}{a+\sin ^2x}dx\\\\
&=\int_0^{\pi}\frac{2}{(2a+1)-a\cos 2x}dx\\\\
&=\int_0^{2\pi}\frac{1}{(2a+1)-\cos x}dx \tag 1
\end{align}$$
Now, we move to the complex plane and let $z=e^{ix}$ in $(1)$.  Thus, $dx=\frac{dz}{iz}$ and we have 
$$I(a)=i\oint_{|z|=1}\frac{2}{z^2-2(2a+1)z+1}dz$$
The pole inside the unit circle is at $z=(2a+1)-\sqrt{(2a+1)^2-1}$.  Thus, using the residue theorem we have
$$\bbox[5px,border:2px solid #C0A000]{I(a)=\frac{\pi}{\sqrt{a(a+1)}}}$$
A: As an alternative to the technique you mentioned above,  you may instead try the substitution $t=\tan(x/2)$. Then the integral will transform into
$$
I(a)=2\int_0^{\infty} \frac{1+t^2}{(1+t^2)^2 a+4t^2}dt\underbrace{=}_{\text{parity}}\int_{-\infty}^{\infty} \frac{1+t^2}{(1+t^2)^2 a+4t^2}dt
$$
Now the problem is reduced to the most elementary type of "residue approach loving integrals". Just use a big semicircle in the upper half plane as an integration contour.
Can you take it from here?
A: Let $z=e^{ix}$ and then $\sin x=\frac{1}{2i}(z-\frac{1}{z})$. So
\begin{eqnarray}
\int_0^\pi\frac{1}{a+\sin^2x}dx&=&\frac12\int_{-\pi}^\pi\frac{1}{a+\sin^2x}dx\\
&=&\frac12\int_{|z|=1}\frac{1}{a-\frac14(z-\frac1z)^2}\frac{1}{iz}dz\\
&=&\cdots
\end{eqnarray}
I think you can do the rest.
A: Assume that $a\not\in[-1,0]$ so that the integral converges.
$$
\begin{align}
&\int_{0}^{\pi}\frac{\mathrm{d}x}{a+\sin^2(x)}\\
&=\frac12\int_0^{2\pi}\frac{\mathrm{d}x}{a+\sin^2(x)}\tag{1}\\
&=\frac12\oint\frac1{a-\left(z-1/z\right)^2/4}\frac{\mathrm{d}z}{iz}\tag{2}\\
&=\frac2i\oint\frac{z}{4az^2-(z^2-1)^2}\mathrm{d}z\tag{3}\\
&=\frac2i\oint\frac1{4aw-(w-1)^2}\mathrm{d}w\tag{4}\\
&=\small\frac1{2i\sqrt{a(a+1)}}\oint\left(\frac1{w-\left(1+2a-2\sqrt{a(a+1)}\right)}-\frac1{w-\left(1+2a+2\sqrt{a(a+1)}\right)}\right)\,\mathrm{d}w\tag{5}\\
&=\left\{\begin{array}{}
+\dfrac\pi{\sqrt{a(a+1)}}&\text{if }a\gt0\\
-\dfrac\pi{\sqrt{a(a+1)}}&\text{if }a\lt-1\tag{6}
\end{array}\right.
\end{align}
$$
Explanation:
$(1)$: symmetry using $\sin^2(x+\pi)=\sin^2(x)$
$(2)$: substitute $z=e^{ix}$
$(3)$: algebra
$(4)$: $w=z^2$; note that as $z$ circles the origin once, $w$ circles twice
$(5)$: partial fractions
$(6)$: note which singularity is in the unit circle
