Calculating $\int_0^\pi \frac{1}{a+b\sin^2(x)} dx $ How do I calculate this integral? $a \gt b$ is given.
$$\int_0^\pi \frac{1}{a+b\sin^2(x)} dx $$
I am confused since WolframAlpha says one the one hand, that $F(\pi) = F(0) = 0 $ , but with some random values  it isn't 0. 
What am I missing?
Note that I am not really interested in a complete antiderivative, I am more interested in a $G(a,b) = F(\pi) - F(0) = \, ... $
 A: The antiderivative
$$
F(x) = \frac{1}{\sqrt{a}\sqrt{a+b}} \arctan\left(\frac{\sqrt{a+b} \tan x}{\sqrt{a}}\right)
$$
given by WA isn't continuous on the whole interval $[0,\pi]$
(because it contains $\tan x$ which jumps at $x=\pi/2$),
and this is why $F(\pi)-F(0)$ doesn't give the right answer.
(Clearly, the answer "zero" is wrong, since the integrand is positive!)
On the other hand, $F(x)$ is continuous on the interval $(-\pi/2,\pi/2)$, and extends continuously to the endpoints by taking limits, and your integrand has period $\pi$ so we can integrate over any interval of length $\pi$ without changing the integral's value. So
$$
\int_0^\pi \frac{1}{a+b\sin^2(x)} dx
= \int_{-\pi/2}^{\pi/2} \frac{1}{a+b\sin^2(x)} dx
= \lim_{x\to(\pi/2)^-} F(x) - \lim_{x\to(-\pi/2)^+} F(x)
= \frac{\pi}{\sqrt{a}\sqrt{a+b}}
$$
works.
You can find some articles about "gotchas" of this kind in computer algebra systems if you search the web for "D. J. Jeffrey continuous".
A: Suppose we seek to evaluate
$$\frac{1}{2} \int_0^{2\pi} \frac{1}{a+b\sin^2 x} dx.$$
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{1}{a+b(z-1/z)^2/4/(-1)}\frac{dz}{iz}
\\ = \frac{1}{2} \int_{|z|=1}
\frac{4}{4a-b(z-1/z)^2}\frac{dz}{iz}
\\ = \frac{2}{i} \int_{|z|=1}
\frac{z}{4a-b(z-1/z)^2}\frac{dz}{z^2}
\\ = \frac{2}{i} \int_{|z|=1}
\frac{z}{4az^2-b(z^2-1)^2} dz
\\ = \frac{2}{i} \int_{|z|=1}
\frac{z}{-bz^4+(2b+4a)z^2-b} dz.$$
The poles here are all simple and located at
$$\rho_{1,2,3,4}
= \pm\sqrt{\frac{2a+b}{b} \pm 
\frac{2\sqrt{a^2+ab}}{b}}.$$
Re-write this as
$$\rho_{1,2,3,4}
= \pm\sqrt{1+\frac{2a}{b} \pm 
\frac{2\sqrt{a^2+ab}}{b}}.$$
With $a$ and  $b$ positive the first two poles  are clearly not inside
the contour (modulus larger than one). That leaves
$$\rho_{3,4}
= \pm\sqrt{1+\frac{2a}{b}
- \frac{2\sqrt{a^2+ab}}{b}}.$$
Now we have
$$1+\frac{2a}{b} 
- \frac{2\sqrt{a^2+ab}}{b} < 1$$
and also
$$1+\frac{2a}{b} 
- \frac{2\sqrt{a^2+ab}}{b} > 0$$
since
$$(b+2a)^2 = b^2+4ab+4a^2 > 4(a^2+ab)$$
and therefore these poles are indeed inside the contour.

The residues are given by
$$\left. \frac{z}{-4bz^3+2(2b+4a)z}
\right|_{z=\rho_{3,4}}
= \left. \frac{1}{-4bz^2+2(2b+4a)}
\right|_{z=\rho_{3,4}}.$$
This is
$$\frac{1}{-4b-8a+8\sqrt{a^2+ab}
+2(2b+4a)}
= \frac{1}{8\sqrt{a^2+ab}}.$$
It follows that the desired value is
$$\frac{2}{i}\times 2\pi i
\times \frac{2}{8\sqrt{a^2+ab}}
= \frac{\pi}{\sqrt{a}\sqrt{a+b}}.$$
