<s>[INST] Evaluate $\int_{0}^{2\pi} \frac{cos \theta}{2 + cos \theta} d\theta$ using the residue theorem My attempt to a solution for $I = \int_{0}^{2\pi} \frac{cos \theta}{2 + cos \theta} d\theta$ is as follows. 
On the unit circle we have $z=e^{i\theta} \implies dz = izd\theta \iff d\theta = \frac{dz}{iz}$, and furthermore $cos \theta = \frac{e^{i\theta} + e^{-i\theta}}{2} = \frac{z+1/z}{2}.$ 
By this variable change and the residue theorem, the integral becomes, $$I = \int_{|z|=1}^{} \frac{(z+1/z)\frac{1}{2}}{(2+\frac{z+1/z}{2})} \frac{dz}{iz} = \frac{1}{i} \int_{|z|=1}^{} \frac{z^2+1}{z(z^2+4z+1)}dz = \frac{1}{i} \int_{|z|=1}^{} \frac{z^2+1}{z(z+2-\sqrt{3})(z+2+\sqrt{3})}dz  = 2\pi i \ \sum_{j=1}^{2}\text{Res}\left[\frac{z^2+1}{z(z+2-\sqrt{3})(z+2+\sqrt{3})}, z_j\right],$$
where, on the unit disc, the integrand $f(z) = \frac{z^2+1}{z(z+2-\sqrt{3})(z+2+\sqrt{3})}$, has a simple pole at $z_1=0$, and one at $z_2=-2+\sqrt{3}$.
Evaluating the residues we obtain $\text{Res}\left[f(z),0\right] = \lim_{z \to 0} \left[\frac{z^2+1}{(z+2-\sqrt{3})(z+2+\sqrt{3})}\right] = \frac{1}{(2-\sqrt{3})(2+\sqrt{3})} = 1$, and  $\text{Res}\left[f(z),-2+\sqrt{3}\right] = \lim_{z \to -2+\sqrt{3}} \left[\frac{z^2+1}{(z+2-\sqrt{3})(z+2+\sqrt{3})}\right] = \frac{(-2+\sqrt{3})^2 +1}{(-2+\sqrt{3})(-2+\sqrt{3} + 2 + \sqrt{3}))} = \frac{8-4\sqrt{3}}{6-4\sqrt{3}} = \frac{4-2\sqrt{3}}{3-2\sqrt{3}}.$
Finally we obtain, $$I = 2\pi i \left(1 + \frac{4-2\sqrt{3}}{3-2\sqrt{3}}\right) = \frac{2\pi i (7-4\sqrt{3})}{3-\sqrt{3}}.$$
However the solution in the text claims the answer to be $I = \pi(1-\frac{2}{\sqrt{3}}).$ And I do not doubt the validity of the texts solution since I agree with how they derived it. However they solved it using a different way which I would never apply my self. 
All help is appreciated. Thanks! 
 [/INST] 
$$I = \int_{|z|=1}^{} \frac{(z+1/z)\frac{1}{2}}{(2+\frac{z+1/z}{2})} \frac{dz}{iz} = \frac{1}{i} \int_{|z|=1}^{} \frac{z^2+1}{z(z^2+4z+1)}dz = \frac{1}{i} \int_{|z|=1}^{} \frac{z^2+1}{z(z+2-\sqrt{3})(z+2+\sqrt{3})}dz  = 2\pi \color{red}{i} \ \sum_{j=1}^{2}\text{Res}\left[\frac{z^2+1}{z(z+2-\sqrt{3})(z+2+\sqrt{3})}, z_j\right]$$

Note that you have an extra factor of $i$ in the last step ($2\pi i \cdot \dfrac{1}{i} = 2\pi$, not $2\pi i$). Also, by rationalizing the denominator, $$\frac{4 - 2\sqrt{3}}{3 - 2\sqrt{3}} = \frac{(4 - 2\sqrt{3})(3 + 2\sqrt{3})}{3^2 - (2\sqrt{3})^2} = \frac{12 - 6\sqrt{3} + 8\sqrt{3} - 12}{9-12} = \frac{2\sqrt{3}}{-3}$$ which is the same as $-\dfrac{2}{\sqrt{3}}$. So the answer should be $$I = 2\pi\left(1 + \frac{4 - 2\sqrt{3}}{3 - 2\sqrt{3}}\right)=2\pi\left(1 - \frac{2}{\sqrt{3}}\right)$$
</s>