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$.
 A: 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.
$$
A: with the hint from above we get
$$\frac{\sin (x)-x \cos (x)}{x \sin (x)+\cos (x)}+C$$
A: Consider the following $$f(x)=\frac{\sin x-x\cos x}{x\sin x+\cos x}$$
$$\implies f'(x)=\frac{d}{dx}\left(\frac{\sin x-x\cos x}{x\sin x+\cos x}\right)=\frac{(x\sin x+\cos x)\frac{d}{dx}(\sin x-x\cos x)-(\sin x-x\cos x)\frac{d}{dx}(x\sin x+\cos x)}{(x\sin x+\cos x)^2}$$ $$ =\frac{(x\sin x+\cos x)(x\sin x)-(\sin x-x\cos x)(x\cos x)}{(x\sin x+\cos x)^2}$$ $$ =\frac{x^2\sin^2 x+x\sin x\cos x-(x\sin x\cos x-x^2\cos^2 x)}{(x\sin x+\cos x)^2}$$ $$ =\frac{x^2\sin^2 x+x\sin x\cos x-(x\sin x\cos x-x^2\cos^2 x)}{(x\sin x+\cos x)^2}$$ $$ =\frac{x^2\sin^2 x+x\sin x\cos x-x\sin x\cos x+x^2\cos^2 x)}{(x\sin x+\cos x)^2}$$ $$ =\frac{x^2(\sin^2 x+\cos^2 x)}{(x\sin x+\cos x)^2}$$ $$f'(x) =\frac{x^2}{(x\sin x+\cos x)^2}$$
Now, integrating both the sides we get $$\int(f'(x))dx=\int \frac{x^2}{(x\sin x+\cos x)^2}$$ $$\implies \int \frac{x^2}{(x\sin x+\cos x)^2}=f(x)+C$$ $$ \int \frac{x^2}{(x\sin x+\cos x)^2}=\frac{\sin x-x\cos x}{x\sin x+\cos x}+C$$
