<s>[INST] Is there a quicker way to solve this integral: $\int \frac{3-\cos(x)}{(1+2\cos(x))\sin^2(x)}dx$? The integral is:
$$ \int \frac{3-\cos(x)}{(1+2\cos(x))\sin^2(x)}dx$$
This is the way I approached it:
$$ \tan\left(\frac{x}{2}\right)=u\\dx=\frac{2}{\sec^2\left(\frac{x}{2}\right)}du$$
By using trigonometric identities we get:
$$ \sin(x)=\frac{2u}{1+u^2};\ \cos(x)=\frac{1-u^2}{1+u^2};\ \sec^2\left(\frac{x}{2}\right)=1+u^2
$$
Therefore the integral now becomes:
$$ 2\int \frac{3-\frac{1-u^2}{1+u^2}}{\left(1+2\left(\frac{1-u^2}{1+u^2}\right)\right)\left(\frac{2u}{1+u^2}\right)^2(1+u^2)}du=$$ $$\int\frac{(1+2u^2)(1+u^2)}{u^2(3-u^2)}du$$ By dividing the two polynomials we get: $$\int\left(-2-\frac{9u^2+1}{u^2(3-u^2)}\right)du$$ Using partial fractions we get to the simplified form: $$\int\left(-2-\frac{1}{3u^2}+\frac{28}{3(3-u^2)}\right)du$$ $$-2u-\frac{1}{3u}+\frac{28\sqrt3}{9}\int\frac{1}{1-\left(\frac{u}{\sqrt3}\right)^2}du \\ -2u-\frac{1}{3u}+\frac{28\sqrt3\tanh^{-1}{\left(\frac{u}{\sqrt3}\right)}}{9}+C$$
By substituting back in for $u$, we get the solution: $$ \bbox[5px,border:2px solid black]{\frac{28\sqrt3\tanh^{-1}{\left(\frac{\tan\left(\frac{x}{2}\right)}{\sqrt3}\right)}}{9}-2\tan\left(\frac{x}{2}\right)-\frac{1}{3}\cot\left(\frac{x}{2}\right)+C}$$
My question is, as you can understand from the title, is there any easier and faster way to solve this integral? If so, how? Thank you.
 [/INST] You can simplify the calculation by using a trigonometric identity and partial fractions before doing the Weierstrass substitution: since $\sin^2{x}=1-\cos^2{x}$, the initial fraction simplifies to
$$ \frac{3-\cos{x}}{(1+2\cos{x})(1+\cos{x})(1-\cos{x})} = \frac{14/3}{1+2\cos{x}} + \frac{-2}{1+\cos{x}} + \frac{-1/3}{1-\cos{x}}. $$
The middle fraction simplifies to a multiple of $\frac{1}{2}\sec^2{\left(\frac{1}{2}x\right)}$, which easily integrates to $-\tan{\frac{1}{2}x}$, and similarly the last fraction is a multiple of $\frac{1}{2}\csc^2{\left(\frac{1}{2}x\right)}$, which integrates to $-\cot{\frac{1}{2}x}$; the other fraction really does need the Weierstrass substitution, but at least the algebra is now much simpler!
</s>