How to use complex analysis to evaluate the trigonometric integral $\int_{0}^{2 \pi}{\frac {\cos \left( x \right) }{2+\cos \left( x \right) }}$ So I have the integral below which I am meant to evaluate using complex analysis. I was thinking to transform this integral and evaluate using the Residue theorem, but the process is incredibly messy and I am doubting if that is correct way to proceed. I know the answer should be $2\,\pi-4/3\,\sqrt {3}\pi$.
$$\int_{0}^{2\,\pi}\!{\frac {\cos \left( x \right) }{2+\cos \left( x
 \right) }}\,{\rm d}x$$
 A: Yes, it's the best approach. Consider:$$\varphi(z)=\frac1z\times\frac{\frac{z+\frac1z}2}{2+\frac{z+\frac1z}2}=\frac{z^2+1}{z^3+4z^2+z}.$$Then$$\int_0^{2\pi}\frac{\cos\theta}{2+\cos\theta}\,\mathrm d\theta=\frac1i\int_{\lvert z\rvert=1}\varphi(z)\,\mathrm dz$$and this number is $2\pi$ times the sum of the residues of $\varphi$ in the unit disk. The poles of $\varphi$ at that disk are located at $0$ and at $-2+\sqrt3$. Now, use the fact that$$\operatorname{res}_{z=0}\left(\frac{z^2+1}{z^3+4z^2+z}\right)=1\text{ and that }\operatorname{res}_{z=-2+\sqrt3}\left(\frac{z^2+1}{z^3+4z^2+z}\right)=-\frac2{\sqrt3}.$$
A: Whatever method you use, we may as well start with $$I:=\int_0^{2\pi}\frac{\cos x dx}{2+\cos x}=2\pi-2J,\,J:=\int_0^{2\pi}\frac{dx}{2+\cos x}.$$To evaluate $J$ by complex analysis, substitute $z=\exp ix$ so our integral is around a circle. You should obtain$$J=\frac{2}{i}\oint_{|z|=1}\frac{dz}{(z+2)^2-3}.$$The integrand has poles at $-2\pm \sqrt{3}$, and the contour encloses one of these, $-2+\sqrt{3}$. The residue there is $$\lim_{z\to-2+\sqrt{3}}\frac{1}{z+2+\sqrt{3}}=\frac{1}{2\sqrt{3}}.$$So $$J=\frac{2}{i}2\pi i\frac{1}{2\sqrt{3}}=\frac{2\pi}{\sqrt{3}},\,I=2\pi-\frac{4\pi}{\sqrt{3}}.$$
