Complex Integration with trignometric function 
Verify that
  $\int_0^{\frac{\pi}{2}}\frac{d\theta}{a+\sin^2\theta}=\frac{\pi}{2[(a(a+1)]^\frac{1}{2}}$

I know that $\sin\theta=\frac{e^{i\theta}-e^{-i\theta}}{2}$ then I did
$$\int_0^{\frac{\pi}{2}}\frac{d\theta}{a+\sin^2\theta}=\int_0^{\frac{\pi}{2}}\frac{d\theta}{a+\frac{1}{4}(e^{i\theta}-e^{-i\theta})^2}=\int_0^{\frac{\pi}{2}}\frac{4d\theta}{4a+(e^{i\theta}-e^{-i\theta})^2}$$
I do not know if this is right but I'm really stuck
 A: Here we go. I'll just indicate the way, ok? Let $z= e^{i\theta}$ So $|z|=1$ and from this $\overline{z} = z^{-1}$. Also: $$\sin \theta = \frac{e^{i\theta}-e^{-i\theta}}{2i} = \frac{z-\overline{z}}{2i} = \frac{1}{2i}\left(z-\frac{1}{z}\right).$$And: $$\frac{{\rm d}z}{{\rm d}\theta} = ie^{i\theta} = iz \implies {\rm d}\theta = \frac{{\rm d}z}{iz.}$$So: $$\int_0^{2\pi}\frac{{\rm d}\theta}{a+\sin^2\theta} = \oint_\gamma \frac{1}{iz} \frac{{\rm d}z}{a + \left(\frac{1}{2i}\left(z-\frac{1}{z}\right)\right)^2},$$where $\gamma$ is the unit circle. Reorganize that last integral, it'll be a rational function. I trust you can do this? Note that: $$\int_0^{\pi/2}\frac{{\rm d}\theta}{a+\sin^2\theta} = \frac{1}{4}\int_0^{2\pi}\frac{{\rm d}\theta}{a+\sin^2\theta}.$$
A: NOTE 1:

First note that then integral diverges if $-1\le a\le 0$.  So, we will assume that either $a>0$ or $a<-1$.


NOTE 2:

We will simplify things quite a bit by first invoking the identity 
  $$\sin^2x=\frac{1-\cos 2x}{2} \tag 1$$
  By simplifying first, we will reduce the denominator of a contour integral from a $4$th degree polynomial to a $2$nd degree one!


SIMPLIFYING THE INTEGRAL
Using the identity $(1)$, the integral of interest $I\equiv \int_0^{\pi/2}\frac{1}{a+\sin^2x}dx$ simplifies to 
$$\begin{align}
I&\equiv \int_0^{\pi/2}\frac{1}{a+\sin^2x}dx\\\\
&=\int_0^{\pi/2}\frac{2}{(2a+1)-\cos 2x}dx\\\\
&=\int_0^{\pi}\frac{1}{(2a+1)-\cos x}dx\\\\
&=\frac12\int_0^{2 \pi}\frac{1}{(2a+1)-\cos x}dx
\end{align}$$

COMPLEX-PLANE ANALYSIS
Now, we will move to the complex plane.  Let $C$ be the unit circle $|z|=1$ in the complex plane.  Then, let $z=e^{ix}$ so that $dz=ie^{ix}dx$, and $\cos x = \frac12 (z+z^{-1})$.  This gives 
$$\begin{align}
I&=\frac12 \oint_C \frac{1}{(2a+1)-\frac12(z+z^{-1})}\frac{dz}{iz}\\\\
&=i \oint_C \frac{1}{z^2-2(2a+1)z+1}dz
\end{align}$$
The roots of $z^2-2(2a+1)+1=0$ are $z=(2a+1)\pm 2\sqrt{a(a+1)}$.  If $a>0$, then the root $(2a+1)-2\sqrt{a(a+1)}<1$ and the root $(2a+1)+2\sqrt{a(a+1)}>1$.  If $a<-1$, then $(2a+1)+2\sqrt{a(a+1)}<1$ and $(2a+1)-2\sqrt{a(a+1)}>1$.

CASE 1:
For $a>0$, the residue of $i \frac{1}{z^2-2(2a+1)z+1}$ is given by
$$\text{Res}\left(i \frac{1}{z^2-2(2a+1)z+1},z=(2a+1)-2\sqrt{a(a+1)}\right)=i\frac{1}{-4\sqrt{a(a+1)}}$$
and the value of the integral $I$ is 
$$\bbox[5px,border:2px solid #C0A000]{I=\int_0^{\pi/2}\frac{1}{a+\sin^2x}dx=\frac{\pi}{2\sqrt{a(a+1)}}}$$
as expected!

CASE 2:
For $a<-1$, the residue of $i \frac{1}{z^2-2(2a+1)z+1}$ is given by
$$\text{Res}\left(i \frac{1}{z^2-2(2a+1)z+1},z=(2a+1)+2\sqrt{a(a+1)}\right)=i\frac{1}{4\sqrt{a(a+1)}}$$
and the value of the integral $I$ is 
$$\bbox[5px,border:2px solid #C0A000]{I=\int_0^{\pi/2}\frac{1}{a+\sin^2x}dx=-\frac{\pi}{2\sqrt{a(a+1)}}}$$
