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.