evaluate the integral Evaluate the integral: 
$$\int_0^{\pi} \frac{\cos 2\theta}{1 -2a\cos \theta +a^2}d\theta$$
The way I approach this problem is: 
since, $\cos \theta = \frac{e^{it} + e^{-it}}{2}$; and $cos 2\theta = Re(z^2)$. Then, the integral will be written as follow: 
$$\frac{1}{2}\int_0^{2 \pi} \frac{Re(z^2)}{1 - 2a \left( \frac{z + z^{-1}}{2}\right) +a^2}dz$$
$$ = \frac{1}{2}\int_0^{2\pi} \frac{-Re(z^2)}{(z-z_1)(z-z_2)}dz$$
where: 
$$z_1 = \frac{(2a^2 - 2) + \sqrt{4(a^4+1)}}{4a}; \; z_2 = \frac{(2a^2 - 2) - \sqrt{4(a^4+1)}}{4a}$$
until here, I don't know how to use the Residue theorem to evaluate the integral. Can someone show me ?
 A: Notice,  the following expression
$$\frac{\cos 2\theta}{1-2a\cos \theta+a^2}=\frac{2\cos^2 \theta-1}{1-2a\cos \theta+a^2}=\frac{A\cos \theta(1-2a\cos \theta+a^2)+B(1-2a\cos \theta+a^2)+C}{1-2a\cos \theta+a^2}$$$$=A\cos \theta+B+\frac{C}{1-2a\cos \theta+a^2}$$
solving for $A, B, C$, we get $$A=-\frac{1}{a}, \ B=-\frac{a^2+1}{2a^2}, \ C=\frac{a^4+1}{2a^2}$$
Now we have
$$\int_{0}^{\pi}\frac{\cos 2\theta}{1-2a\cos \theta+a^2}d\theta$$ $$=\int_{0}^{\pi}\frac{2\cos^2 \theta-1}{1-2a\cos \theta+a^2}d\theta$$
$$=\int_{0}^{\pi}\left(-\frac{1}{a}\cos\theta-\frac{a^2+1}{2a^2}+\frac{a^4+1}{2a^2}\frac{1}{1-2a\cos \theta+a^2}\right)d\theta$$
$$=-\frac{1}{a}\int_{0}^{\pi}\cos\theta d\theta-\frac{a^2+1}{2a^2}\int_{0}^{\pi} d\theta+\frac{a^4+1}{2a^2}\int_{0}^{\pi}\frac{1}{1-2a\cos \theta+a^2}d\theta$$
$$=0-\frac{(a^2+1)\pi}{2a^2}+\frac{a^4+1}{2a^2}\int_{0}^{\pi}\frac{1}{(a^2+1)-2a\cos \theta}d\theta$$
$$=-\frac{(a^2+1)\pi}{2a^2}+\frac{a^4+1}{4a^3}\int_{0}^{\pi}\frac{1}{\frac{(a^2+1)}{2a}-\cos \theta}d\theta$$
Now, set $\cos\theta=\frac{1-\tan^2\frac{\theta}{2}}{1+\tan^2\frac{\theta}{2}}$.
I hope you can take it from here.
A: Another way is to use the following Fourier expansion: for $|a| < 1$,
$$ \frac{1-a^2}{1 - 2a\cos\theta + a^2} = \sum_{n=-\infty}^{\infty} a^{|n|} e^{in\theta} = 1 + 2 \sum_{n=1}^{\infty} a^n \cos(n\theta). $$
This series immediately gives us
$$ \int_{0}^{\pi} \frac{\cos n\theta}{1 - 2a\cos\theta + a^2} \, dx = \frac{\pi a^n}{1-a^2}, \quad n = 1, 2, \cdots. $$
