How to calculate $\int_0^\pi \frac{\cos^4(x)}{1+\sin^2(x)}dx$ using contour integrals How do I go about calculating $\int_0^\pi \frac{\cos^4(x)}{1+\sin^2(x)}dx$ using contour integrals?
 A: Suppose we seek to evaluate
$$J = \int_0^{\pi} \frac{\cos^4 x}{1+\sin^2 x} dx
= \frac{1}{2} \int_0^{2\pi} \frac{\cos^4 x}{1+\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{(z+1/z)^4/2^4}{1+(z-1/z)^2/(2i)^2} \frac{dz}{iz}
\\ = -\frac{1}{8} \int_{|z|=1}
\frac{(z^2+1)^4}{-4z^2+(z^2-1)^2} \frac{dz}{iz^3}
\\ = \frac{i}{8} \int_{|z|=1}
\frac{(z^2+1)^4}{(z^2-1)^2-4z^2} \frac{z\; dz}{z^4}.$$
Now put  $w=z^2$ so that  $z\; dz =  \frac{1}{2} \; dw$ and  note that
this loops around  the origin twice so that we  must multiply a single
loop by two to get
$$2\times \frac{i}{8} \int_{|w|=1}
\frac{(w+1)^4}{(w-1)^2-4w} \frac{1}{2} \frac{dw}{w^2}
\\ = \frac{i}{8} \int_{|w|=1}
\frac{(w+1)^4}{w^2-6w+1} \frac{dw}{w^2}.$$
In  addition to the  double pole  at $w=0=\rho$  there are  two simple
poles here at
$$\rho_{0,1} = 3 \pm 2\sqrt{2}$$
and clearly  $\rho_1$ is the only  one inside the contour. 
Converting to partial fractions we get
$$\frac{64}{w^2-6w+1} + 1 + \frac{10}{w} + \frac{1}{w^2}.$$ 
Hence the non-zero contribution comes from
$$\frac{64}{w^2-6w+1} + \frac{10}{w}.$$ 
The first term yields
$$\mathrm{Res}_{w=\rho_1} 
\frac{64}{w^2-6w+1} = 
\left. \frac{64}{2w-6} \right|_{w=\rho_1}
\\ = \frac{64}{-4\times\sqrt{2}}
= -\frac{16}{\sqrt{2}} = -8\sqrt{2}.$$
The second  term produces $10$  by inspection. Collecting
everything we have
$$2\pi i \times \frac{i}{8}
\times(10 - 8\sqrt{2})
= \frac{\pi}{4} (8\sqrt{2}-10)$$
or
$$\bbox[5px,border:2px solid #00A000]{
\frac{\pi}{2}(4\sqrt{2}-5).}$$
A: By symmetry,
$$ I = \int_{0}^{\pi}\frac{\cos(x)^4}{1+\sin(x)^2}\,dx = 2 \int_{0}^{\pi/2}\frac{\cos(x)^4}{1+\sin(x)^2}\,dx $$
and by substituting $x=\arctan(t)$ we get
$$ I = 2 \int_{0}^{+\infty}\frac{dt}{(1+t^2)^2 (1+2t^2)}=\int_{-\infty}^{+\infty}\frac{dt}{(1+t^2)^2(1+2t^2)}. $$
The integrand function is now a meromorphic function with double poles at $t=\pm i$, simple poles at $t=\pm\frac{i}{\sqrt{2}}$, bounded by $\frac{C}{|t|^2}$ as $|t|\to +\infty$. By the ML lemma and the residue theorem it follows that:
$$ I = 2\pi i\sum_{\xi\in\{i,i/\sqrt{2}\}}\!\!\!\text{Res}\left(\frac{1}{(1+t^2)^2(1+2t^2)},t=\xi\right)=2\pi i\left(\frac{5i}{4}-i\sqrt{2}\right)=\color{red}{\frac{\pi}{2}(4\sqrt{2}-5)}. $$
