I am trying to evaluate by using contour integration:
$$\int_{0}^{2\pi}\frac{1}{1+\cos^2(\theta)}d\theta$$
From "Fundamentals of Complex Analysis," I have the following two formulas:
$$d\theta = \frac{dz}{iz}, \cos(\theta)=\frac{1}{2}(z+\frac{1}{z})$$ which allow me to rewrite the integral as follows:
$$\int_{C_1}\frac{dz}{iz(1+\frac{1}{4}(z+\frac{1}{z})^2)}=\int_{C_1}\frac{4zdz}{iz^2(4+(z+\frac{1}{z})^2)}=\int_{C_1}\frac{4zdz}{i(4z^2+(z^2+1)^2)}=\int_{C_1}\frac{4zdz}{i((2z-(z^2+1)i)(2z+(z^2+1)i))}=\int_{C_1}\frac{4zdz}{(z^2+2iz+1)(iz^2+2z+i)}$$
For the contour $C_1$, a circle of radius $1$ about the origin, traversed once. When I find the roots of the polynomials on the bottom, I get: $-i\pm i\sqrt{2}$ and $i \pm i\sqrt{2}$.
Then, I find that $$Res(-i+i\sqrt{2})=\frac{1}{2\sqrt{2}}$$
$$Res(i-i\sqrt{2})=\frac{1}{2\sqrt{2}}$$
$$\implies \int_{0}^{2\pi}\frac{1}{1+\cos^2(\theta)}d\theta=2\pi i \times (\frac{1}{2\sqrt{2}}+\frac{1}{2\sqrt{2}})=\pi i \sqrt{2}$$
However, shouldn't the value of this integral be real since the original integral is real-valued?
The same approach but with only one residue to evaluate: \begin{align*} \int_{0}^{2\pi}\frac{d\theta}{1+\cos^2(\theta)}&=\int_{0}^{2\pi}\frac{2d\theta}{3+\cos(2\theta)}=\int_{0}^{4\pi}\frac{dt}{3+\cos(t)}=2\int_{0}^{2\pi}\frac{dt}{3+\cos(t)}\\&=\frac{4}{i}\int_{|z|=1}\frac{dz}{6z+z^2+1} =8\pi\,\mbox{Res}\left(\frac{1}{6z+z^2+1},-3+2\sqrt{2}\right)\\&= \frac{8\pi}{6+2(-3+2\sqrt{2})}=\pi\sqrt{2}. \end{align*}