<s>[INST] Find $\int\limits_{0}^{2\pi} \frac{1}{5-3\cos(x)} \,\,dx$ I have to find $$\int_0^{2\pi} \frac{1}{5-3\cos(x)} \,\,dx$$
I tried to do it by substitution $t = \tan(\frac{x}{2})$
Then we have that $$\cos(x) = \frac{1-t^2}{1+t^2} \quad dx = \frac{2\,dt}{1+t^2}$$ but then also limits of integration are changing so we have
$$\int\limits_{t(0)}^{t(2\pi)} \frac{1}{5 - \frac{1-t^2}{1+t^2}} \cdot \frac{2dt}{1+t^2} = \int\limits_0^0 \frac{1}{5 - \frac{1-t^2}{1+t^2}} \cdot \frac{2\,dt}{1+t^2} = 0$$
I figured out that it is not correct because $\tan(\frac{\pi}{2})$ is not defined and $t(\pi) = \tan(\frac{\pi}{2})$ and $\pi \in [0, 2\pi]$. How can I "repair" that and do it right?
 [/INST] While there have been several clean and different approaches shown here, I'm surprised that nobody has shown that contour integration works well also.  To that end here we go....
Let $z=e^{ix}$ so that $dx=dz/iz$ and $\cos x = \frac12 (z+z^{-1})$.  We have 
$$\begin{align}
I&=\int_0^{2\pi} \frac{1}{5-3\cos x}dx\\\\
&=\oint_C \frac{1}{5-3\frac12 (z+z^{-1})}\frac{dz}{iz}\\\\
&=\oint_C \frac{\frac23 i}{(z-3)(z-1/3)}dz\\\\
&=2\pi i \text{Res}_{\text{in C}} \left(\frac{\frac23 i}{(z-3)(z-1/3)}\right)
\end{align}$$
where $C$ is the unit circle in the complex $z$-plane.  
Note that the pole at $z=1/3$ is inside the unit circle whereas the pole at $z=3$ is outside the unit circle.  
Thus, the residue is given by 
$$\text{Res}_{z=1/3} \left(\frac{\frac23 i}{(z-3)(z-1/3)}\right)=\frac23 i\,\lim_{z\to 1/3}\left((z-1/3)\,\frac{1}{(z-3)(z-1/3)}\right)=-i/4$$
which after multiplying by $2\pi i$ shows that 
$$I=\pi/2$$
as expected!
</s>