Evaluation of $\int \limits _0 ^{2 \pi} \frac {(r \cos \phi +x) \cos(n\phi)} {r^2+2xr \cos \phi +x^2} d\phi$ How to compute
$$\int \limits _0 ^{2 \pi} \frac {(r \cos \phi +x) \cos(n\phi)} {r^2+2xr \cos \phi +x^2} d\phi ?$$
The answer I am provided with is $\dfrac {(-1)^n\pi r^n} {x^{n+1}}$ for $\ x>r$, but I have no idea whether this is actually correct and how to get this.

Suppose we seek to evaluate
$$\int_0^{2\pi} \frac{(r\cos\phi+x)\cos(n\phi)}{r^2+2xr\cos\phi+x^2}
\; d\phi.$$
Introduce $z=\exp(i\phi)$ so that $dz=iz \; d\phi$ to get
$$\int_{|z|=1}
\frac{(r(z+1/z)/2+x)(z^n+1/z^n)/2}{r^2+xr(z+1/z)+x^2}
\frac{dz}{iz}
\\ = \frac{1}{4i} \int_{|z|=1}
\frac{(r(z+1/z)+2x)(z^n+1/z^n)}{(r^2+x^2)z + xrz^2 + xr}
\; dz.$$
The denominator may be factored manually and we get
$$(xz+r)(rz+x)$$
so the poles are at $z=0$ and
$$\rho_0 = -r/x
\quad\text{and}\quad 
\rho_1 = -x/r$$
and with $r \lt x$ only $\rho_0$ is inside the contour.
We get for the residue at $\rho_0$
$$\frac{1}{4i} \left.
\frac{(r(z+1/z)+2x)(z^n+1/z^n)}{(r^2+x^2) + 2xrz}
\right|_{z=-r/x}
\\ = \frac{(-1)^n}{4i} 
\frac{(-r^2/x - x + 2x)((r/x)^n+(x/r)^n)}
{r^2+x^2-2r^2}
\\ = \frac{(-1)^n}{4ix} ((r/x)^n+(x/r)^n).$$
Supposing that  $n$ is  a non-negative integer  the only
remaining contribution is from the pole at zero of
$$\frac{1}{4i} \int_{|z|=\epsilon}
\frac{1}{z^n}
\frac{r(z+1/z)+2x}{(r^2+x^2)z + xrz^2 + xr}
\; dz.$$
Observe that
$$\frac{1}{(xz+r)(rz+x)}
= \frac{1}{x^2-r^2}\frac{1}{z+r/x}
- \frac{1}{x^2-r^2}\frac{1}{z+x/r}.$$
and that
$$[z^n] \frac{1}{z-\beta} =
\frac{1}{\beta} [z^n] \frac{1}{z/\beta-1}
= - \frac{1}{\beta^{n+1}}.$$
so that on performing coefficient extraction we obtain
$$\frac{1}{4i} \frac{1}{x^2-r^2}
\left(-r(-x/r)^{n-1}+r(-r/x)^{n-1}
- r(-x/r)^{n+1}+r(-r/x)^{n+1}
\\ - 2x(-x/r)^{n}+2x(-r/x)^{n}\right).$$
This is
$$\frac{1}{4i} \frac{1}{x^2-r^2} (-x/r)^{n-1}
(-r-r(-x/r)^2-2x(-x/r))
\\+ \frac{1}{4i} \frac{1}{x^2-r^2} (-r/x)^{n-1}
(r+r(-r/x)^2+2x(-r/x))
\\ = \frac{1}{4i} \frac{1}{x^2-r^2} (-x/r)^{n-1}
(-r+x^2/r)
\\+ \frac{1}{4i} \frac{1}{x^2-r^2} (-r/x)^{n-1}
(-r+r^3/x^2)
\\ = \frac{1}{4i} \frac{1}{r} (-x/r)^{n-1}
- \frac{1}{4i} \frac{r}{x^2} (-r/x)^{n-1}
\\ = - \frac{1}{4i} \frac{1}{x} (-x/r)^{n}
+ \frac{1}{4i} \frac{1}{x} (-r/x)^{n}.$$
Finally collect the contributions from both poles to get
$$2\pi i \times \frac{(-1)^n}{4ix}
\left(-(x/r)^n + (r/x)^n + (r/x)^n + (x/r)^n\right)
\\ = 2\pi i \times \frac{(-1)^n}{4ix}
\times 2 (r/x)^n
\\ = \frac{\pi (-1)^n}{x} \left(\frac{r}{x}\right)^n.$$
