<s>[INST] Integral $\int_0^{\pi} \frac{\cos(2018x)}{5-4\cos{x}}dx$ I wish to evaluate  $$I(2018)=\int_{0}^{\pi}\frac{\cos(2018x)}{5-4\cos x} dx$$ Considering $$X=I(k)+iJ(k)=\int_{-\pi}^{\pi}\frac{\cos{kx}}{5-4\cos x} dx +i\int_{-\pi}^{\pi}\frac{\sin{kx}}{5-4\cos x} dx=\int_{-\pi}^{\pi}\frac{e^{ikx}}{5-4\cos x} dx$$ let us substitute $$e^{ix}=z\rightarrow dx=\frac{dz}{iz} \, ,|z|=1$$ Due to Euler's formula we can rewrite $$\cos x=\frac{z^2+1}{2z}$$ $$X=\oint_{|z|=1} \frac{z^k}{5-4\frac{z^2+1}{2z}}\frac{dz}{iz}=\frac{1}{i}\oint_{|z|=1} \frac{z^k}{-2z^2+5z-2}dz$$ $$-2z^2+5z-2=-\frac{1}{2}((2z)^2-5(2z)+4)=-\frac{1}{2}(2z-4)(2z-1)=-2(z-2)(z-\frac{1}{2})$$ Now let us notice that in our contour $|z|=1\,$ only the pole $z_2=\frac{1}{2}$ is found. Thus the integral we seek to evaluate is $$\frac{1}{i} \cdot 2\pi i \, \text{Res} (f(z),z_2)$$ where $f(z)=\frac{z^k}{-2(z-2)(z-\frac{1}{2})}$ $$X=2\pi \lim_{z\to z_2} (z-z_2)\frac{z^k}{-2(z-2)(z-z_2)}=\frac{2}{3}\pi \frac{1}{2^k}$$ therefore $$I(k)=\Re (X) =\frac{2\pi}{3}\frac{1}{2^k}$$ And $$\int_{0}^{\pi}\frac{\cos(2018 x)}{5-4\cos x} dx=\frac{\pi}{3}\cdot\frac{1}{2^{2018}}.$$ Now someone told me that the answer is $0$ and I am wrong (also wolfram gives $0$ as an answer). Could you please clarify? Or maybe give another solution to this integral if it's $0$ or another answer? 
 [/INST] I am going to show the general case:
$$
I_n=\int_{0}^{\pi} \frac{\cos nx}{5-4 \cos x} d x= \frac{\pi}{3 \cdot 2^{n}}
$$
using contour integration on the unit circle $|z|=1$.
Noting $I_n= \frac{1}{2} \int_{0}^{2\pi} \frac{\cos nx}{5-4 \cos x} dx=\frac{1}{2} Re(J_n)$, where
$$J_n=\int_{0}^{2\pi} \frac{e^{nxi}}{5-4 \cos x} dx$$
Let $ z=e^{xi}, $ then $ dz=i z   dx.$
$$
\begin{aligned}
J _n &=\oint_{|z \mid=1} \frac{z^{n}}{5-4\left(\frac{z+z^{-1}}{2}\right)} \frac{d z}{z i} \\
&=i \oint_{|z|=1} \frac{ z^{n}}{(2 z-1)(z-2)} d z
\end{aligned}
$$
The integrand has a simple pole within $|z|=1$ at $\frac{1}{2} $, and the residue is
\begin{aligned}
\operatorname{Res}\left(\frac{z^{n}}{(2 z-1)(z-2)}, z=\frac{1}{2}\right)=& \lim _{z \rightarrow \frac{1}{2}}\left(z-\frac{1}{2}\right) \cdot \frac{z^{n}}{(2 z-1)(z-2)} \\
=& -\frac{1}{3 \cdot 2^{n}}\end{aligned}
$$
J_{n}=i \cdot 2 \pi i \cdot\left(-\frac{1}{3 \cdot 2^{n}}\right)=\frac{\pi}{3 \cdot 2^{n-1}}
$$
Plugging $J_n$ back yields the result.
$$
\boxed{I_{n}=\frac{1}{2} Re\left(J_{n}\right)=\frac{\pi}{3 \cdot 2^{n}}}
$$
As a bonus, $$\int_{0}^{\pi} \frac{\sin nx}{5-4 \cos x} d x=0$$
</s>