<s>[INST] Finding indefinite integral $\int \frac{x^2}{(x \sin x + \cos x)^2} dx $ I need hint in finding the integral of
$$\int \frac{x^2}{(x \sin x + \cos x)^2} dx $$
I tried dividing the term by $x^2\cos^2x$ and then substituting $\tan x$.
 [/INST] From the formula
$$
D\frac fg=\frac{f'g-fg'}{g^2},
$$
we might guess that we have a quotient $f/g$ with $g=x\sin x+\cos x$, but what is then $f$?
First, we note that
$$
g'=x\cos x.
$$
Well, with the trig-one, we can write
$$
\begin{aligned}
\frac{x^2}{(x\sin x+\cos x)^2}
&=\frac{x^2\sin^2x+x^2\cos^2x}{(x\sin x+\cos x)^2}
=\frac{x\sin x(x\sin x+\cos x)-x\cos x(\sin x-x\cos x)}{(x\sin x+\cos x)^2}\\
&=\frac{x\sin x\cdot g-g'\cdot (\sin x-x\cos x)}{(x\sin x+\cos x)^2}.
\end{aligned}
$$
By pattern matching, $f=\sin x-x\cos x$ (note that, then $f'=x\sin x$).
We conclude that our guess was lucky, and that
$$
\int \frac{x^2}{(x\sin x+\cos x)^2}\,dx = \frac{\sin x-x\cos x}{x\sin x+\cos x}+C.
$$
</s>