How to Evaluate $ \int \! \frac{dx}{1+2\cos x} $ ? 
Possible Duplicate:
How do you integrate $\int \frac{1}{a + \cos x} dx$? 

I have come across this integral and I tried various methods of solving. The thing that gets in the way is the constant $2$ on the $\cos(x)$ term. I tried the conjugate (works without the 2$\cos x$), Weierstrass Substitution (not sure if I was applying it correctly), and others. Is there a way to solve this integral elegantly or some unknown (sneaky) trick when you come across families of similar integrals as this one?:
$$ \int \! \frac{dx}{1+2\cos x} $$
 A: Weierstrass substitution works for this integral, and it's not even that messy to work with. 
Substitute $\tan \frac{x}{2} = t$, so that $\cos x = \frac{1-t^2}{1+t^2}$ and $dx = \frac{2dt}{1+t^2}$. Then the integral reduces to
$$
\int \frac{dx}{1+2 \cos x} = \int \frac{\frac{2}{1+t^2}}{1 + \frac{2(1-t^2)}{1+t^2}} dt = \int  \frac{2}{1+t^2 + 2 - 2t^2} dt =  \int \frac{2}{3-t^2} dt.
$$
To evaluate the final integral, we can use the method of partial fractions:
$$
\frac{2}{3-t^2} = \frac{1}{\sqrt{3}} \left( \frac{1}{t + \sqrt{3}} - \frac{1}{t - \sqrt{3}} \right).
$$
A: $I=\int \frac{\mathrm{d}x}{1+2\cos x}$
$=\int\frac{\mathrm{d}x}{\sin^2(x/2)+\cos^2(x/2)+2(\cos^2(x/2)-\sin^2(x/2))}$
$=\int \frac{\mathrm{d}x}{3\cos^2(x/2)-\sin^2(x/2)}$
Multiply the Nr and the Dr of the integrand by  $\sec^2 (x/2)$.
You will get:
$\int \frac{\sec^2(x/2)\mathrm{d}x}{3-\tan^2(x/2)}$
Substitution:
$z=\tan(x/2)$
$\mathrm{d}z=1/2 \sec^2(x/2) \mathrm{d}x$
Therefore,
Integral=$\int \frac {2\mathrm{d}z}{3-z^2}$
$=\int \frac{1}{\sqrt{3}}(\frac{1}{\sqrt{3}+z}+\frac{1}{\sqrt{3}-z})\mathrm{d}z$ 
A: Generalization:
Let's consider $\cos x = \frac{1-t^2}{1+t^2}; t = \tan\frac{x}{2}; dx=\frac{2}{1+t^2} dt.$ Then we get that our integral becomes:
$$J = \int \frac{2dt}{(a+b)+(a-b) t^2}$$
I. For the case $a>b$, consider $a+b=u^2$ and  $a-b=v^2$, and obtain that:
$$J = 2\int \frac{dt}{u^2+v^2 t^2}=\frac{2}{uv} \arctan\frac{vt}{u} +C.$$
Turning back to our notation we get:
$$I=\frac{2}{\sqrt{a^2-b^2}} \arctan\left(\sqrt{\frac{a-b}{a+b}} \tan\frac{x}{2} \right) + C.$$
II. For the case $a<b$, consider $a+b=u^2$ and  $a-b=-v^2$, and obtain that:
$$J = 2\int \frac{dt}{u^2-v^2 t^2}=\frac{1}{uv}\ln\frac{u+vt}{u-vt} \ +C.$$
Turning back again  to out initial notation and have that:
$$I=\frac{2}{\sqrt{b^2-a^2}} \ln\frac{b+a \cos x + \sqrt{b^2-a^2} \sin x}{a+b \cos x} + C.$$
Also, note that $x$ must be different from ${+}/{-}\arccos(-\frac{a}{b})+2k\pi$ if $|\frac{a}{b}|\leq1$.
Q.E.D.
