Integrate $\int_0^{2\pi}\frac{dx}{(2+\cos(x))}$ using complex integral theorem Would someone help me to integrate 
$$\int_0^{2\pi}\frac{dx}{(2+\cos(x))}$$  
by means of residue theorem? 
 A: Hint. Use the substitution $z=e^{ix}$. Then $2\cos(x)=z+\frac{1}{z}$, $dz=iz\cdot dx$ and
$$I:=\int_0^{2\pi}\frac{dx}{(2+\cos(x))}=\int_{|z|=1}\frac{1}{2+\frac{z+\frac{1}{z}}{2}}\cdot \frac{dz}{iz}.$$
Then apply Residue Theorem:
$$I=\frac2i\int_{|z|=1}\frac{dz}{z^2+4z+1}=4\pi \cdot\mbox{Res}\left(\frac{1}{z^2+4z+1},\sqrt{3}-2\right)
=\frac{4\pi}{2(\sqrt{3}-2)+4}=\frac{2\pi}{\sqrt{3}}.
$$
A: Use $z=e^{ix}$, then
$$
\begin{align}
\int_0^{2\pi}\frac1{2+\cos(x)}\,\mathrm{d}x
&=\oint_{|z|=1}\frac1{2+\frac{z+\frac1z}2}\frac{\mathrm{d}z}{iz}\\
&=\frac2i\oint_{|z|=1}\frac{\mathrm{d}z}{z^2+4z+1}\\
&=\frac1{i\sqrt3}\oint_{|z|=1}\left(\frac1{z+2-\sqrt3}-\frac1{z+2+\sqrt3}\right)\mathrm{d}z\\
&=\frac1{i\sqrt3}(2\pi i-0)\\[3pt]
&=\frac{2\pi}{\sqrt3}
\end{align}
$$
A: Passing into the complex plane with the substitution
$$\cos x \to \cos z = \frac{\left(z + z^{-1}\right)}{2} ~~~~~~~ \text{d}x = \frac{\text{d}z}{iz}$$
an you get:
$$\int_{|z| = 1} -i \frac{\text{d}z}{z\left(2 + \frac{z + z^{-1}}{2}\right)} = \int_{|z| = 1} -2i \frac{\text{d}z}{z\left(4 + \frac{z^2 + 1}{z}\right)}$$
Arrange the terms:
$$\int_{|z| = 1} -2i \frac{\text{d}z}{4z + z^2 + 1}$$
Now calculate the poles, solving $z^2 + 4z +1  = 0$
The first pole (solution) is $z = -2+\sqrt{3}$ inside the unit circle and it's ok.
The second one is $z = -2-\sqrt{3}$ outside the unit circle so it's not ok.
Result:
$$2\pi i\ \text{Res}_{z = -2+\sqrt{3}}\ (z - 2-\sqrt{3})\frac{-2i}{(z-2-\sqrt{3})(z-2+\sqrt{3})} = \frac{2\pi}{\sqrt{3}}$$
A: A real-analytic alternative:
$$ I = \int_{0}^{\pi}\frac{d\theta}{2+\cos\theta}+\int_{0}^{\pi}\frac{d\theta}{2-\cos\theta} = 4\int_{0}^{\pi}\frac{d\theta}{4-\cos^2\theta}=8\int_{0}^{\pi/2}\frac{d\theta}{4-\cos^2\theta}$$
and by substituting $\theta=\arctan t$
$$ I = 8 \int_{0}^{+\infty}\frac{dt}{4t^2+3}=\color{red}{\frac{2\pi}{\sqrt{3}}}. $$
