<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] 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$$
</s>