<s>[INST] Evaluating integral with residues I'm trying to evaluate the following integral: $$\int_0^{2\pi} \frac{d\theta}{8\cos^2 (\theta) + 1}$$ using residues. To begin, assume $z(t) = e^{i\theta}$ is a parametrization of the unit circle, for $0 \le \theta \le 2\pi$, so that $dz = ie^{i\theta} d\theta$. Making the necessary substitution, our integral becomes
$\int_C \frac{dz/(iz)}{2z^2 + 2z^{-2} + 5}$ , where $C$ is the circle $|z|=1$. Evaluating this integral yields
\begin{align}
\int_C \frac{dz/(iz)}{2z^2 + 2z^{-2} + 5} & = \frac{1}{i} \int_C \frac{dz}{2z^3 + 2z^{-1} + 5z} = \frac{1}{i}\int_C \frac{zdz}{2z^4 + 5z^2 + 2}
\end{align}
To solve for singularities, let $u = z^2$ and substitute this into the denominator to get $2u^2 +5u+2=0$. Solving for $u$ with the quadratic formula yields $u = -2,-1/2$. Thus, $f(z)$ has singularities at $z_0 = i\sqrt(2), z_1 = -i\sqrt(2), z_2 = -i\sqrt(2)/2,$ and $z_3 = i\sqrt(2)/2$. Only $z_2$ and $z_3$ are within the unit circle, so we need only consider those. Thus, the integral above is just $$\int_0^{2\pi} \frac{d\theta}{8\cos^2 (\theta) + 1} = \frac{1}{i}(2\pi i) \big(\text{Res}(f; -i\sqrt{2}/2) + \text{Res}(f; i\sqrt{2}/2)\big).$$ Since both singularities are simple poles, and that $P(a) \neq 0$ and $Q(a) = 0$ for either point, we know that $$\text{Res}(f; a) = \frac{P(a)}{Q'(a)} = \frac{z}{8z^3 + 10z}.$$ However, for when I evaluate this quantity I get the wrong answer. Where did I go wrong?
 [/INST] First of all I suggest the use of the identity $2\cos^2(\theta)=\cos(2\theta)+1$ in order to have a second degree polynomial at the denominator (later you will have to compute just ONE residue).
$$I:=\int_0^{2\pi} \frac{d\theta}{8\cos^2 (\theta) + 1}=\int_0^{2\pi} \frac{d\theta}{4\cos(2\theta)+4 + 1}=\int_0^{2\pi} \frac{d t}{4\cos(t)+5}$$
where $t=2\theta$, and we used the fact that the $\frac{1}{4\cos(t)+5}$ has period $2\pi$.
Hence, by letting $z = e^{i t}$, we get
$$\begin{align}I&=\int_{|z|=1} \frac{1}{2(z+1/z)+5}\cdot \frac{dz}{iz}=\frac{1}{i}\int_{|z|=1} \frac{dz}{2z^2+5z+2}\\&=2\pi\mbox{Res}\left(\frac{1}{2z^2+5z+2},-\frac{1}{2}\right)=2\pi\left(\frac{1}{4(-1/2)+5}\right)=\frac{2\pi}{3}.\end{align}$$
Note that your procedure is correct. At the final step you should get
$$\begin{align}I&= 2\pi \left(\text{Res}\left(\frac{z}{2z^4 + 5z^2 + 2}, -\frac{i}{\sqrt{2}}\right) + \text{Res}\left(\frac{z}{2z^4 + 5z^2 + 2}, \frac{i}{\sqrt{2}}\right)\right)\\&=2\pi\left(\frac{1}{8(-1/2)+10}+\frac{1}{8(-1/2)+10}\right)=\frac{2\pi}{3}.\end{align}$$
</s>