Evaluating a real integral using complex methods Let's say I want to evaluate the following integral using complex methods - 
$$\displaystyle\int_0^{2\pi} \frac {1}{1+\cos\theta}d\theta$$
So I assume this is not very hard to be solved using real analysis methods, but let's transform the problem for the real plane to the complex plane, and instead calculate - 
$$\begin{aligned}\displaystyle\int_0^{2\pi} \frac {1}{1+\cos\theta}d\theta \quad&\Longrightarrow \quad [ z=e^{i\theta} , |z| =1]\\
&\Longrightarrow \quad\displaystyle\int_{|z|=1} \frac {1}{1+\frac{z+\frac{1}{z}}{2}}\frac{dz}{iz}\end{aligned}$$
So now after few algebric fixed this is very easily solvable using the residue theorem.
My question is why can I just decide that I want to change the integration bounds for $[0,2\pi]$ to $|z|=1$. If I wanted to change the integrating variable to $z=e^{i\theta}$ aren't the integration bounds suppose to transform to $[1,1]$ (because $e^{i2\pi k}=1$)? I'm just having hard time figuring out why is this mathematicaly a right transform.
Thanks in advance!
 A: Maybe you're confusing what $\mid z\mid =1$ means. It simply is the equation of a circle of radius $1$ and it is slightly ill-defined in the context of the integral. When you make that transform, you must specify the bounds on $\theta$. In this case it is: $0 \le \theta \le 2\pi$.
This integral's antiderivative may be computed using real analysis. You may use Weierstrass Substitution using which you get $$\int\dfrac{\mathrm dx}{1+\cos(x)}=\tan\biggl(\dfrac{x}{2}\biggr)+C=\dfrac{\sin x}{\cos x+1}+C$$Note however the integral is divergent, it diverges to $+\infty$.
A: $1+\cos\theta$? Are you sure that's the right problem? That's a second-order pole in the path of integration - or, equivalently, a $\frac{c}{(\theta-\pi)^2}$ singularity in the real form. By an elementary comparison, this one's $\infty$.
If we apply the complex form anyway, we get $\int_{|z|=1}\frac{-2i}{(z+1)^2}\,dz$. That has an antiderivative $\frac{2i}{z+1}$ defined everywhere except one point $z=-1$. If it were some random loop containing $1$, we could just evaluate that antiderivative at the endpoints $1$ and $1$ to get zero. Is that the number your residue calculation gave you (because the residue at that pole is zero)?
Unfortunately, the pole is in our path. Because it's a second-order pole, not even principal values will save us. The integral blows up, and we fall back on real methods to show that it specifically diverges to $+\infty$.
Now, in general, converting a $\int_0^{2\pi}\,d\theta$ integral to a $\int_{|z|=1}\,dz$ integral is standard practice. We need the function of $\theta$ being integrated to be periodic of period $2\pi$ so that the function of $z$ will be continuous, but it's simply the standard parametrization $z=e^{i\theta}$ applied in reverse.
Oh, and this integral, or something similar like $\int_0^{2\pi}\frac1{1+a\cos\theta}\,d\theta$ isn't too bad with real methods. While solving them the complex way is a reasonable exercise, it's certainly not the only choice. The antiderivative is even elementary.
