# Calculating \$int frac{dx}{(a+bcosx)^2}\$

(Here, a>b.)

My attempt consisted of converting the cos to half-angle tangents, substitutimg the half-angle tangent for t, and simplifying to $$int frac{2(1+t^2)dt}{((a+b)+(a-b)t^2)^2}$$
From here, I multipilied and divided the integrand by (a-b), and added an $$(a+b)-2b$$ to the numerator, and simplified it to $$frac{4b}{a-b}int frac{dt}{((a+b)+(a-b)t^2)^2} + frac{2t}{a-b}$$
Now just looking at the integral left, I substituted t for $$sqrt{frac{a+b}{a-b}} tantheta$$, did some simplifying, converted the resulting $$cos^2 theta$$ in the numerator to $$1+cos2 theta$$, and wrapped up the integral, finishing up with $$frac{2tan frac{x}{2}}{a-b}-frac{2b}{(a^2-b^2)^{frac{3}{2}}}(arctan sqrt{frac{a+b}{a-b}tan frac{x}{2}+ frac{sqrt{ frac{a+b}{a-b}tan frac{x}{2}}{1+{ frac{a+b}{a-b}tan^2 frac{x}{2}})$$

This is, apparently, wrong. Can someone help me with why?