Evaluating $ \int_0^\pi \frac{\cos{n\theta}}{1 -2r\cos{\theta}+r^2} d\theta $ How do I go about evaluating the following integral:
$$ \int_0^\pi \frac{\cos{n\theta}}{1 -2r\cos{\theta}+r^2} d\theta $$
for $n \in \mathbb{N}$, and  $r \in (0,1)$?
My trick has been to rewrite, using the exponential form of $\cos$, as:
$$ \int_0^\pi  \frac{e^{ni\theta} + e^{-ni\theta}}{2(1 - re^{i\theta})(1-re^{-i\theta})} d\theta.$$
Letting $z = e^{i\theta}$ and $d\theta = \frac{1}{iz}dz$, we get
$$ \frac{1}{2i}\int_{|z|=1}  \frac{z^n + \frac{1}{z}^n}{(1 - rz)(z-r)} d\theta $$
This would have a singularity when $z= e^{i\theta} = r$  or when $zr = re^{i \theta} = 1$. Since $r \in (0,1)$ neither of these can occur. So we just need to integrate the above, but I can't see any way about this?
Is my approach valid or along the right lines, and how can I proceed?
 A: The contour integration way:
Residue theorem reveals within a second that 
$$\int_0^\pi \frac{\cos{n\theta}}{1 -2r\cos{\theta}+r^2} d\theta=\pi\frac{r^n}{1-r^2}.$$
Note: To make everything simpler (compared with what you tried in your post) it is enough to use in the numerator $e^{i n\theta}$.
The real method way:
Exploit carefully the well-known series result (which can be proved by real methods)
$$\sum_{n=1}^{\infty} p^n \sin(n x)=\frac{p\sin(x)}{1-2 p \cos(x)+p^2}, |p|<1$$
A: The given integral is $I=\frac12\Re(J)$ where $J=\int_0^{2\pi}\frac{e^{in\theta}}{1-2r\cos\theta+r^2}d\theta$. As OP did, we substitute $z=e^{i\theta}$ to get, for $r>1$,
$$J=\frac{i}{r}\int_{|z|=1}\frac{z^n}{(z-r)(z-\frac1r)}=\frac{i}{r}2\pi i\left(Res_{z=\frac1r}\frac{z^n}{(z-r)(z-\frac1r)}\right)=-\frac{2\pi} r\frac{r^{-n}}{\frac1r-r}=\frac{2r^{-n}}{r^2-1}\pi.$$
Hence, $J$ is real and $I=\frac12J=\frac{r^{-n}}{r^2-1}\pi.$
Example: $n=2$ and $r=5$. Then $I=\frac{5^{-2}}{5^2-1}\pi=\frac{\pi}{600}$ which is in agreement with WA.
For $r\in(0,1)$, we take the other root and get $I=\large\frac{r^{n}}{1-r^2}\pi.$
A: Let $f$ be some function analytic in some region containing the unit disc $|z|\le1$. Then due to Poisson integral formula, it is true for $0\le r<1$ that
$$
\Re[f(re^{i\phi})]={1\over2\pi}\int_{-\pi}^\pi{1-r^2\over1-2r\cos(\theta-\phi)+r^2}f(e^{i\theta})\mathrm d\theta.
$$
Let $f(z)=z^n$ and $\phi=0$, so we have
$$
{r^n\over1-r^2}={1\over2\pi}\int_{-\pi}^\pi{\cos(n\theta)\over1-2r\cos(\theta)+r^2}\mathrm d\theta=\frac1\pi\int_0^\pi{\cos(n\theta)\over1-2r\cos(\theta)+r^2}\mathrm d\theta.
$$
