<s>[INST] Evaluating $\int \frac{l\sin x+m\cos x}{(a\sin x+b\cos x)^2}dx$ How do I integrate this expression:
$$\int \frac{l\sin x+m\cos x}{(a\sin x+b\cos x)^2}dx$$.I got this in a book.I do not know how to evaluate integrals of this type.
 [/INST] Use the famous equation
$$ a\cos x + b\sin x = \pm \sqrt{a^2 + b^2}\cos\left(x - \arctan(b/a)\right)$$
and let $\alpha = \arctan(b/a)$
to get
$$
\begin{aligned}
\mathcal{J}&=\int\dfrac{\ell \sin x + m\cos x}{(a^2 + b^2)\cos^2\left(x - \alpha\right)}\,\mathrm{d}x\\
&=\frac{1}{a^2 + b^2}\int\dfrac{\ell\sin(x - \alpha+\alpha) + m\cos(x-\alpha + \alpha)}{\cos^2\left(x-\alpha\right)}\,\mathrm{d}x\\
&=\frac{1}{a^2+b^2}\int\dfrac{\ell\left[\sin(x-\alpha)\cos\alpha + \sin\alpha\cos(x-\alpha)\right]+m\left[\cos(x-\alpha)\cos\alpha-\sin(x-\alpha)\sin\alpha\right]}{\cos^2\left(x-\alpha\right)}\,\mathrm{d}x\\
&=\frac{1}{a^2+b^2}\int\frac{\sin(x-\alpha)\left(\ell\cos\alpha-m\sin\alpha\right) + \cos(x-\alpha)\left(\ell\sin\alpha+m\cos\alpha\right)}{\cos^2\left(x-\alpha\right)}\,\mathrm{d}x\\
&=\dfrac{\ell\cos\alpha-m\sin\alpha}{a^2+b^2}\int\sec(x-\alpha)\tan(x-\alpha)\,\mathrm{d}x+\dfrac{\ell\sin\alpha+m\cos\alpha}{a^2+b^2}\int\sec(x-\alpha)\,\mathrm{d}x\\
&=\dfrac{\ell\cos\alpha-m\sin\alpha}{a^2+b^2}\sec(x-\alpha) + \dfrac{\ell\sin\alpha+m\cos\alpha}{a^2+b^2}\ln\left|\sec(x-\alpha)+\tan(x-\alpha)\right|+C.
\end{aligned}
$$
And we are done.
</s>