Two different results with residue calculus for the integral $\int_{0}^{2\pi}\frac{\cos(3x)}{5-4\cos(x)}dx$. What went wrong? So I have to evaluate the following integral :$$\int_{0}^{2\pi}\frac{\cos(3x)}{5-4\cos(x)}dx$$ So I solve as usual with the residue theorem and by using $\cos(3x)= Re(e^{3ix})$, $\cos(x)=\frac{e^{ix}+e^{-ix}}{2}$ and $z=e^{ix}$, but then I have some troubles evaluating the residues. I get as poles 2 and $\frac{1}{2}$ where only $\frac{1}{2}$ is in our domain (circle of radius 1). 
When I calculate the residue using $\frac{g(z)}{f'(z)}$, I get $\frac{\frac{1}{2^3}}{5-2}=\frac{1}{24}$ (I put the i outside, that's not the problem here) but when I use $\lim_{z \to \frac{1}{2}} (z-\frac{1}{2})\frac{z^3}{-(z-2)(z-\frac{1}{2})}$, I get $\frac{1}{12}$ so that when I multiply by $2 \pi $ (again the i is not the problem here), I get $\frac{\pi}{6}$. WolframAlpha gets $\frac{\pi}{12}=2\pi *\frac{1}{24}$ so my second way of finding the residue ($\frac{1}{12}$-->$\frac{\pi}{6}$) seems to be wrong. My question is, what did I do wrong ?
 A: Well, you arrived at: $$I=\int_{|z|=1}\frac{z^3}{5-4\left(\frac{z+ z^{-1}}{2}\right)}\frac{dz}{iz}$$
With some algebra the integral reduces to : $$\int_{|z|=1}\frac{z^3}{5z-2(z^2+1)}\frac{dz}{i}=\frac{1}{i}\int_{|z|=1}\frac{z^3}{-2z^2+5z-2}dz=$$
$$=\frac{1}{i}\int_{|z|=1}\frac{z^3}{-(z-2)(2z-1)}dz=\frac{1}{2i}\int_{|z|=1}\frac{z^3}{-(z-2)(z-\tfrac12)}dz$$
Now here you can see that when you factored that denominator you forgot that additional $\frac12$ and everything should be fine now.
A: Starting with a geometric series:
$$\frac{1}{2-e^{ix}} = \sum_{n\geq 0}\frac{1}{2^{n+1}}e^{nix}$$
we may consider the product between this series and its conjugate:
$$\begin{eqnarray*}\frac{1}{5-4\cos x}&=&\sum_{m,n\geq 0}\frac{1}{2^{m+n+2}}e^{(n-m)ix}\\&=&\frac{1}{3}+\sum_{n>m\geq 0}\frac{1}{2^{m+n+1}}\cos((n-m)x)\\&=&\frac{1}{3}+\sum_{d\geq 1}\cos(dx)\sum_{m\geq 0}\frac{1}{2^{2m+d+1}}\\&=&\frac{1}{3}+\sum_{d\geq 1}\frac{\cos(dx)}{2^d}\sum_{m\geq 0}\frac{1}{2^{2m+1}}\\&=&\frac{1}{3}+\frac{2}{3}\sum_{d\geq 1}\frac{\cos(dx)}{2^d}\end{eqnarray*} $$
to get the whole Fourier cosine series of $\frac{1}{5-4\cos x}$. Then by the orthogonality relations
$$ \int_{0}^{2\pi}\frac{\cos(3x)}{5-4\cos(x)}\,dx = \frac{2\pi}{3}\cdot\frac{1}{2^3}=\color{red}{\frac{\pi}{12}}.$$
This approach might look as an overkill, but it is pretty useful in understanding the asymptotic behaviour of the Fourier coefficients of $\frac{1}{\left(R\pm\cos\theta\right)^\alpha}$ when $\alpha\in\frac{1}{2}+\mathbb{N}$.
