Integration of a trigonometric function I am having some difficulties with the calculation of the following integral. Can somebody help me please? 
$$\int \frac{dx}{1+a\cos x},\text{ for }0<a<1$$
Thank you in advance
 A: Detailed hint:
Wikipedia calls this the The Weierstrass Substitutiion: when $t=\tan(\theta/2)$,
$$
\begin{align}
\sin(\theta)&=\frac{2t}{1+t^2}\\
\cos(\theta)&=\frac{1-t^2}{1+t^2}\\
\tan(\theta)&=\frac{2t}{1-t^2}\\
\mathrm{d}\theta&=\frac{2\mathrm{d}t}{1+t^2}
\end{align}
$$
A: Hint 1: $\cos x=\frac{1-t^2}{1+t^2}$ which $t=\tan\frac{x}{2}$.
Hint 2: $t=\tan\frac{x}{2}\Rightarrow dt=\frac{1}{2}\sec^2\frac{x}{2}dx=\frac{1}{2}(t^2+1)dx$.
A: Substitute, $t = \tan \left(\dfrac x2\right)$. So $x = 2\tan^{-1}t$ and $dx = \dfrac{2dt}{1+t^2}$. And the integral becomes, 
$$\begin{align*}\int\dfrac{\dfrac{2}{1+t^2}}{1+\dfrac{a(1-t^2)}{1+t^2}}dt
&=\dfrac2{(1+a)}\int\dfrac1{1+\left[t\dfrac{\sqrt{1-a}}{\sqrt{1+a}}\right]^2}dt
&\color{blue}{u =\left[t\frac{\sqrt{1-a}}{\sqrt{1+a}}\right]\Rightarrow dt = \frac{\sqrt{1+a}}{\sqrt{1-a}}du }\\
&=\dfrac2{(1+a)}\frac{\sqrt{1+a}}{\sqrt{1-a}}\int\dfrac1{1+u^2}du
&\color{blue}{\int\dfrac1{1+u^2}du= \tan^{-1}u}\\
\\&=\dfrac2{(1+a)}\frac{\sqrt{1+a}}{\sqrt{1-a}}\tan^{-1}u\\\\
&=\dfrac2{\sqrt{1-a^2}}\tan^{-1}u&\color{blue}{u =\left[t\frac{\sqrt{1-a}}{\sqrt{1+a}}\right]}\\ \\
&=\dfrac{2\tan^{-1}\left[\frac{\sqrt{1-a}}{\sqrt{1+a}}\cdot\tan \left(\dfrac x2\right)\right]}{\sqrt{1-a^2}}\\\\
\end{align*}$$
$$\displaystyle\Large\therefore \boxed{\int \dfrac1{1+acosx}dx =\dfrac{2\tan^{-1}\left[\frac{\sqrt{1-a}}{\sqrt{1+a}}\cdot\tan \left(\dfrac x2\right)\right]}{\sqrt{1-a^2}} }$$
