Integrating $\frac{1}{(a+b\cos x)}$ 
Question: How do you prove this integral$$\int\frac {dx}{a+b\cos x}=\frac 2{\sqrt{a^2-b^2}}\arctan\left\{\tan\frac x2\sqrt{\frac {a-b}{a+b}}\right\}$$or$$\int\frac {dx}{a+b\cos x}=\frac 1{\sqrt{b^2-a^2}}\log\frac {\sqrt{b+a}+\sqrt{b-a}\tan\tfrac x2}{\sqrt{b+a}-\sqrt{b-a}\tan\tfrac x2}$$According as $a> b$ and $a<b$.

I'm not entirely sure how to prove the two integrals. I started off with the identity$$\cos x=\frac {1-\tan^2\tfrac x2}{1+\tan^2\tfrac x2}$$And substituted to get$$\begin{align*}\int\frac {dx}{a+b\cos x} & =\int\frac {dx}{a+b\left(\tfrac {1-\tan^2\tfrac x2}{1+\tan^2\tfrac x2}\right)}\\\\ & =\int\frac {1+\tan^2\tfrac x2}{(a+b)+(a-b)\tan^2\tfrac x2}\, dx\\ & =\int\frac {dz}{(a+b)+(a-b)z^2}\end{align*}$$where $z=\tan\tfrac x2$. Using the rule$$\int\frac 1{x^2+a^2}\, dx=\frac 1a\arctan\frac xa$$I get the integral as$$\frac 1{\sqrt{a+b}}\arctan\left\{\frac z{\sqrt{a+b}}\sqrt{a-b}\right\}=\frac 1{\sqrt{a+b}}\arctan\left(\tan\frac x2\sqrt{\frac {a-b}{a+b}}\right)$$Which doesn't match up with the solutions given. I'm also not sure how the second solution comes up.

Lets compute the integral using the half tangent angle sub where
$$
\cos x = \frac{1-t^2}{1+t^2}
$$
where $t = \tan\left(\frac{x}{2}\right)$
we obtain and integral of the form
$$
\int \frac{1}{a+b\left[\frac{1-t^2}{1+t^2}\right]}\frac{2}{1+t^2}dt
$$
or
$$
\int \frac{2}{a(1+t^2)+b(1-t^2) }dt
$$
or
$$
\int \frac{2}{a+b + (a-b)t^2}dt
$$
you can re-arrange to obtain
$$
\frac{2}{a+b}\int\frac{1}{1 + \lambda^2t^2}dt
$$
where $\lambda^2 = \frac{a-b}{a+b}$
so we have
or using $\lambda t = u\to dt = \frac{1}{\lambda }du$ we find
which is
$$
\frac{2}{\lambda (a+b)}\int\frac{1}{1 +  u^2}du
$$
which is easily integrated.
For the case where $b > a$ we have to look at 
$$
-\lambda^2 = \frac{a-b}{a+b} < 0 \to 
$$
so we have
you can re-arrange to obtain
$$
\frac{2}{a+b}\int\frac{1}{1 - \lambda^2t^2}dt = \frac{2}{a+b} \int \frac{1}{(1-\lambda t)(1+\lambda t)}dt
$$
we can split the final integrand as follows
$$
\frac{1}{(1-\lambda t)(1+\lambda t)} = \frac{1}{2}\left[\frac{1}{1-\lambda t} + \frac{1}{1+\lambda t}\right]
$$
so you end up with an integral of the form
$$
\frac{2}{a+b}\int\frac{1}{1 - \lambda^2t^2}dt = \frac{1}{a+b} \int \left[\frac{1}{1-\lambda t} + \frac{1}{1+\lambda t}\right] dt
$$
which is once again sdtraightforward to integrate.
