# Integrating with the residue theorem (trigonometric function)

My question is about the following integration using the residue theorem. $$f(x)=\int_0^{2\pi} \frac{\cos(x)}{5-4\cos(x)}dx$$

Using $$z=e^{ix},\; 2\;cos(x)= z+z^{-1},\; dz=\frac{1}{zi}$$ I am able to get the equation $$f(z)= i/2 \int_C \frac{(z^2+1)}{z(2z-1)(z-2)}$$ and the corresponding residues: $$\operatorname{Res}(z=0)=\lim_{z\rightarrow0} zf(z) = -\frac{i}{4}$$ $$\operatorname{Res}(z=0.5)=\lim_{z\rightarrow0.5} (z-0.5)f(z) = \frac{5i}{12}$$ $$\operatorname{Res}(z=2)=\lim_{z\rightarrow2} (z-2)f(z) = -\frac{5i}{12}$$ From the residue theorem, for closed curve $$f(z)$$ $$\int_C f(z)\,dz= 2\pi i \cdot \sum \operatorname{Res}(f(z))=\pi/2.$$ From WolframAlpha's computation magic, the actual value is $$\pi/3$$. I've checked my arithmetic half a dozen times and I am at my wits end. I suspect my mistake is somewhere is variable transformation of $$dx$$ to $$dz$$ but I could not figure out what.

Could anyone kindly help me with this.

The path $$C$$ has $$|z|=1$$. So we shouldn't consider $$z=2$$ which is outside $$C$$.
$$R(0) = \frac{i}{2}\lim_{z\to0}\frac{z(z^2+1)}{z(2z-1)(z-2)} = \frac{i}{2}\frac{1}{(-1)(-2)} = \frac{i}{4}$$
and $$R(0.5) = \frac{i}{2}\lim_{z\to{0.5}}\frac{(z-0.5)(z^2+1)}{2z(z-0.5)(z-2)} = \frac{i}{4}\frac{5/4}{(1/2)(-3/2)} = -\frac{5i}{12}$$ So, $$I = 2\pi i[R(0)+R(0.5)] = 2\pi i\bigg[\frac{i}{4}-\frac{5i}{12}\bigg] = 2\pi i \bigg[\frac{-2i}{12}\bigg]= \frac{\pi}{3}$$