1. Thank you very much. I suspected an error there, but I didn't see it at all. I'll be careful next time.

2. I've done that error so many times myself!

3. Your poles are outside the contour, because their magnitudes are both greater than pi, which is the radius of the semi-circle.

So, your integral from -pi to pi has become equal to the negative of the integral along the semicircle, since the total integral is, as you've mentioned, zero. So, now you have to compute the negative of the integral along the semicircle. How will you propose to do that?

4. Originally Posted by Ackbeet
Your poles are outside the contour, because their magnitudes are both greater than pi, which is the radius of the semi-circle.

So, your integral from -pi to pi has become equal to the negative of the integral along the semicircle, since the total integral is, as you've mentioned, zero. So, now you have to compute the negative of the integral along the semicircle. How will you propose to do that?
I'm sure I'm not understanding well. Here is what I believe (but I know is false): $\displaystyle \int _{- \pi}^{\pi} \frac{d \theta}{2 \cos (\theta )} = \oint _ C \frac{dz}{1+ 2 \cos (z )}=0$ according to Cauchy's integral theorem. With C being the closed contour of the semi circle going from -pi to pi and being in the 2 first quadrants (upper ones).

5. I think you are making this way too hard and I think the value of your integral is incorrect.

Here is goes First as Olpeg noted is that

$\displaystyle \displaystyle \int_{0}^{\pi}\frac{d\theta}{2+\cos(\theta)}=\frac {1}{2}\int_{0}^{2\pi}\frac{d\theta}{2+\cos(\theta) }$

Now use the substitution $\displaystyle z=e^{i\theta} \implies dz=ie^{i\theta}d\theta \iff d\theta =\frac{dz}{iz}$

Note that $\displaystyle \cos(\theta)=\frac{e^{i\theta}+e^{-i\theta}}{2}=\frac{z+z^{-1}}{2}$

Now we sub all of this into the integral to get

$\displaystyle \displaystyle \int_{0}^{\pi}\frac{d\theta}{2+\cos(\theta)}=\frac {1}{2}\oint_{|z|=1}\frac{1}{(2+\frac{z+z^{-1}}{2})}\frac{dz}{iz}=\frac{1}{i}\oint\frac{dz}{z^ 2+4z+1}=$
$\displaystyle \displaystyle \frac{1}{i}\oint \frac{dz}{(z+2-\sqrt{3})(z+2+\sqrt{3})}$

Now there is only one pole in the interior of the unit circle $\displaystyle z=-2+\sqrt{3}$

So now by the residue theorem we get
$\displaystyle \displaystyle \frac{1}{i}\oint \frac{dz}{(z+2-\sqrt{3})(z+2+\sqrt{3})}=\frac{1}{i}2\pi i \left( \frac{1}{-2+\sqrt{3}+2+\sqrt{3}}\right)=\frac{\pi}{\sqrt{3}}$

6. Thanks TheEmptySet. Could you justify the step $\displaystyle \frac{1}{i}\oint \frac{dz}{(z+2-\sqrt{3})(z+2+\sqrt{3})}=\frac{1}{i}2\pi i \left( \frac{1}{-2+\sqrt{3}+2+\sqrt{3}}\right)$? I know that the line integral is worth $\displaystyle 2 \pi i \sum res (f,-2+\sqrt 3 )$.
I also don't understand well the method. Why did we choose a circle with radius 1? Why not say with radius 0.1 so that we enclose no pole and the integral is worth 0? I never understood the method of complex analysis to calculate real integrals.

7. I don't think we are really choosing a contour. Think of it this way. When you have a line integral with respect to z, to evaluate it you choose a contour (if you are not given one) and then do a substitution(say for a circular contour, it is $\displaystyle z = r\,e^{i\theta}$).

However, in this problem you need to go the other way, since you are already given theta. In essence, the contour has already been chosen for you.

8. Originally Posted by arbolis
Thanks TheEmptySet. Could you justify the step $\displaystyle \frac{1}{i}\oint \frac{dz}{(z+2-\sqrt{3})(z+2+\sqrt{3})}=\frac{1}{i}2\pi i \left( \frac{1}{-2+\sqrt{3}+2+\sqrt{3}}\right)$? I know that the line integral is worth $\displaystyle 2 \pi i \sum res (f,-2+\sqrt 3 )$.
I also don't understand well the method. Why did we choose a circle with radius 1? Why not say with radius 0.1 so that we enclose no pole and the integral is worth 0? I never understood the method of complex analysis to calculate real integrals.
When you have a simple pole at $\displaystyle z=a$. Then the residue at $\displaystyle a$ is
$\displaystyle \displaystyle \lim_{z \to a}(z-a)f(z)$

So in the case above we have

Res$\displaystyle (f,z=-2+\sqrt{3})$$\displaystyle \displaystyle =\lim_{z\to -2+\sqrt{3}}(z+2-\sqrt{3})\frac{1}{(z+2-\sqrt{3})(z+2+\sqrt{3})}=\frac{1}{2\sqrt{3}}$

9. Reply to arbolis at post # 19:

Actually, part of what you wrote down is correct. What you're not seeing is that the integral in the middle of your equation is composed of two integrals, which, when summed, add up to an integral that's equal to zero. Let $\displaystyle C_{1}$ be defined as the segment on the real axis from $\displaystyle -\pi$ to $\displaystyle \pi$. Let $\displaystyle C_{2}$ be the semicircle path from $\displaystyle \pi$ to $\displaystyle -\pi$ all in the upper half plane. Then what you've really got is this:

$\displaystyle \displaystyle{\oint_{C}\frac{dz}{2+\cos(z)}=\int_{ C_{1}}\frac{dz}{2+\cos(z)}+\int_{C_{2}}\frac{dz}{2 +\cos(z)}=0.}$

$\displaystyle \displaystyle{\int_{0}^{\pi}\frac{d\theta}{2+\cos( \theta)}=\frac{1}{2}\int_{-\pi}^{\pi}\frac{dz}{2+\cos(z)}.}$
$\displaystyle \displaystyle{\int_{0}^{\pi}\frac{d\theta}{2+\cos( \theta)}=-2\int_{C_{2}}\frac{dz}{2+\cos(z)}.}$