Help with Coordinate Transformation from Polar Coordinates? I want to evaluate the integral $$\frac{1}{2\pi} \int_0^{2\pi} \frac{1}{1 - 2r \cos \theta + r^2} d\theta. $$  I thought first to substitute $\cos(\theta)$ for $\frac{1}{2} (e^{i\theta} + e^{-i\theta} ) $, reducing the problem to a complex integral over the unit circle, then using the $ z = re^{i\theta}$ to change the polar coordinate of $d\theta$ to $dz$.  However, I am stuck with the r in the term when I try to change coordinates using $dz = ire^{i\theta} d\theta$.
Basically I want to be able to integrate over $dz$ instead of $d\theta$ but for some reason I'm finding it difficult to transform the coordinate planes, due to the lingering polar terms when I try to to make the transformation. Is there some generic method that I can generally use when I'm faced with the problem of making coordinate changes?
 A: The idea to transform everything as an integral of a function of the complex variable over the unit circle $C$ is a good one. As you wrote, this means you want to use $z=\mathrm{e}^{\mathrm{i}\theta}$, $\mathrm{d}z=\mathrm{i}\mathrm{e}^{\mathrm{i}\theta}\mathrm{d}\theta=\mathrm{i}z\mathrm{d}\theta$, and $2\cos\theta=z+1/z$. Your integral becomes 
$$
\frac1{2\pi\mathrm{i}}\int_Cf(z)\mathrm{d}z,
$$
with
$$
f(z)=\frac1{z(1+r^2-r(z+1/z))}=\frac1{z(1+r^2)-rz^2-r}=\frac1{(r-z)(rz-1)}.
$$
The rest is a matter of residues computation: you will want to know the poles of $f$ inside the circle $C$ hence whether $r<1$ or $r>1$ will matter (the case $r=1$ being excluded since the integral then diverges) and, surprise, the result will involve an absolute value sign.
A: Hint: This is related to the Poisson Kernel.
Full Solution: I assume $0<r<1$.  Notice that
$$  \frac{1-r^2}{1-2r\cos\theta +r^2} = \operatorname{Re}\left(\frac{1+re^{i\theta}}{1-re^{i\theta}}\right)$$  so that
$$\frac{1}{2\pi} \int_0^{2\pi} \frac{1}{1 - 2r \cos \theta + r^2} d\theta=\frac{1}{2\pi(1-r^2)} \operatorname{Re}\left(\int_0^{2\pi} \left(\frac{1+re^{i\theta}}{1-re^{i\theta}}\right)d\theta\right).$$  Making the change of variables $z=re^{i\theta}$, $dz=ire^{i\theta}d\theta$ this becomes
$$\frac{1}{1-r^2}\operatorname{Re}\left(\frac{1}{2\pi i}\int_{C_r}\frac{1+z}{z(1-z)}dz\right)=\frac{1}{1-r^2}$$ where the last equality comes from evaluating the residue at $0$.
Remark: If $r>1$ the same solution will work, but we will pick up a residue at $z=1$ of $-2$ and instead get $$\frac{1}{2\pi} \int_0^{2\pi} \frac{1}{1 - 2r \cos \theta + r^2} d\theta=\frac{1}{r^2-1}$$ as the final answer.
Hope that helps,
A: Here's a way that one might be "led by the nose" to the correct contour integral.. Looking at the denominator $r^2 - 2r\cos\theta + 1$ as a function of $r$, you can use the quadratic formula to get the roots, given by 
$$r = \cos(\theta) \pm {1 \over 2}\sqrt{4\cos^2(\theta) - 4}$$
$$= \cos(\theta) \pm {1 \over 2}\sqrt{-4\sin^2(\theta)}$$
$$ = \cos(\theta) \pm i \sin(\theta)$$
$$ = e^{i\theta}, e^{-i\theta}$$
So your integral is the same as 
$${1 \over 2\pi} \int_0^{2\pi} {d\theta \over (r - e^{i\theta})(r - e^{-i\theta})}$$
This suggests doing a contour integral over the unit circle, with $z = e^{i\theta}$, 
${1 \over z} = e^{-i\theta}$, and $dz = ie^{i\theta}d\theta$, so that $d\theta = {dz \over iz}$. The resulting contour integral is
$${1 \over 2\pi i} \int_{|z| = 1}{dz \over z(r - z)(r - {1 \over z})}$$
$$= {1 \over 2\pi i} \int_{|z| = 1}{dz \over (r - z)(rz - 1)}$$
Note this is the same contour integral Didier Piau got, and as he indicated it's a pretty routine application of the residue theorem. 
