Solve trigonometric integral $\int \frac{\mathrm dx}{(a+b\cos x)^2}$ Source: Question bank on challenging integral problems for high school students. An advanced level problem
Problem: Evaluate the indefinite integral: 
$$\int \frac{\mathrm dx}{(a+b\cos x)^2}$$ given that $a>b$
My try on it: It seems simple enough but upon  a deeper look I can't find a suitable substitution for it. Not even going to try integrating by parts! Tried constructing a function whose integral is the one above. Gotten close results but not quite it. And that is not the correct approach anyway! Also tried using Partial fractions by constructing a function 
$${1\over(a+by)^2} = {Ay+B\over(a+by)^2} + {Cy+D\over a+by}$$
Pretty unsure about this one. Am I going right or can you please suggest a better, quicker alternative. I can upload the answer if someone needs to refer it.
 A: $$
\int \frac{\mathrm dx}{(a+b\cos x)^2}
$$
At this hour I am not clever so I'll just pound on this until it yields, as follows. Michael Spivak's calculus textbook says the "world's sneakiest substitution" is the tangent half-angle substitution, and that it is used with rational functions of sine and cosine (it can also be used to solve some differential equations):
\begin{align}
\tan\frac x 2 & = u \\[10pt]
x & = 2\arctan u \\[10pt]
dx & = \frac{2\,du}{1+u^2} \\[10pt]
\cos x & = \text{[ here apply the double-angle formula for the cosine} \\
& \qquad \text{and then that stuff about drawing right triangles ]} \\[10pt]
& = \frac{1-u^2}{1+u^2}.
\end{align}
This is due to Euler and often erroneously attributed to Weierstrass.
\begin{align}
& \int \frac{dx}{(a+b\cos x)^2} = \int \frac{\left( \frac{2\,du}{1+u^2} \right)}{\left( a + b\frac{1-u^2}{1+u^2} \right)^2} = \int \frac{2(1+u^2)\, du}{(a(1+u^2)+b(1-u^2))^2} \\[10pt]
= {} & 2 \int \frac{(1+u^2)\,du}{((a-b)u^2 + (a+b))^2} = \cdots
\end{align}
Now notice that if $a+b>0$ and $a-b<0,$ then the denominator can be factored without using imaginary numbers, but if $a+b$ and $a-b$ are both positive you need other methods. Or more generally if $a+b$ and $a-b$ have opposite signs then you can factor the denominator (and then use partial fractions) and if they have the same sign, then you work with an irreducible quadratic factor in the denominator.
A: Utilize the simpler integral result
$$\int \frac{dx}{a+b\cos x}=\frac2{\sqrt{a^2-b^2}}\tan^{-1}
 \frac{\tan \frac x2 }{ \sqrt{\frac{a+b}{a-b}}}
$$
and integrate both sides of the equation below
$$\left( \frac{\sin x}{a+b\cos x}\right)’ 
= \frac{a}{b(a+b\cos x)}- \frac{a^2-b^2}{b(a+b\cos x)^2}
$$
to obtain
$$\int \frac{dx}{(a+b\cos x)^2}= \frac{b\sin x}{(b^2-a^2)(a+b\cos x)}+ \frac{2a}{(a^2-b^2)^{3/2}}\tan^{-1}
 \frac{\tan \frac x2 }{ \sqrt{\frac{a+b}{a-b}}}
$$
