find the value of $\int \frac {x^2}{({x\sin x+\cos x})^2}\,dx$ In my textbook this question solved in this way:
they take since $$\dfrac{d}{dx}(x\sin x+\cos x)=x\cos x $$  so,
$$\int \dfrac {x^2}{({x\sin x+\cos x})^2}\,dx$$
$$\int \dfrac {x\cos x}{({x\sin x+\cos x})^2}\cdot \dfrac {x}{\cos x}\,dx$$
Is there any other way to do this question? I know substitution, but I have never encountered this type of arrangement on the basis of the differential.
 A: Let $u=x\sin{x}+\cos{x}$ so that $du=x\cos{x}~dx$. Note that we chose this since $u$ is composed within another function. Unfortunately, $x\cos{x}$ doesn't quite appear in the integral, but's let's use wishful thinking and pretend that it did. Thus, we can easily solve an integral of the following form:
$$
\int \dfrac {x\cos x}{({x\sin x+\cos x})^2}\,dx = \int \dfrac {1}{u^2}\,dx =\dfrac{u^{-1}}{-1}+K=\dfrac{-1}{x\sin x + \cos x}+K
$$
Now in order to make the above work useful, we multiply by $1$ in a fancy way so that $x\cos{x}$ appears in the integral:
$$\int \dfrac{x^2}{(x\sin{x}+\cos{x})^2} dx = \int \dfrac{x}{\cos{x}} \cdot \dfrac{x\cos{x}}{(x\sin{x}+\cos{x})^2} dx $$
Now we use integration by parts. By pattern matching, this suggests that we let $f=\dfrac{x}{\cos{x}}$ and $dg=\dfrac {x\cos x}{({x\sin x+\cos x})^2}\,dx$. Then $df=\dfrac{x\sin{x}+\cos{x}}{\cos^2{x}}dx$ and $g=\dfrac{-1}{x\sin x + \cos x}$, which yields:
$$ \begin{align*}
\int \dfrac{x^2}{(x\sin{x}+\cos{x})^2} dx &= \int \dfrac{x}{\cos{x}} \cdot \dfrac{x\cos{x}}{(x\sin{x}+\cos{x})^2} dx \\
&= \dfrac{x}{\cos{x}} \cdot \dfrac{-1}{x\sin x + \cos x} - \int \dfrac{-1}{x\sin x + \cos x} \cdot \dfrac{x\sin{x}+\cos{x}}{\cos^2{x}}dx \\
&= \dfrac{-x}{\cos x (x\sin{x}+\cos{x})} + \int \sec^2 {x}~dx \\
&= \dfrac{-x}{\cos x (x\sin{x}+\cos{x})} + \tan{x} + C \\
&= \dfrac{-x}{\cos x (x\sin{x}+\cos{x})} + \dfrac{\sin{x}}{\cos{x}} + C \\
&= \dfrac{-x + \sin x (x\sin{x}+\cos{x})}{\cos x (x\sin{x}+\cos{x})} + C \\
&= \dfrac{-x(\sin^2 x + \cos^2 x) + \sin x (x\sin{x}+\cos{x})}{\cos x (x\sin{x}+\cos{x})} + C \\
&= \dfrac{(-x\sin^2 x  -x\cos^2 x) + (x\sin^2{x}+\sin{x}\cos{x})}{\cos x (x\sin{x}+\cos{x})} + C \\
&= \dfrac{\sin{x}\cos{x}-x\cos^2 x}{\cos x (x\sin{x}+\cos{x})} + C \\
&= \dfrac{\cos{x}(\sin{x}-x\cos x)}{\cos x (x\sin{x}+\cos{x})} + C \\
&= \dfrac{\sin{x}-x\cos x}{x\sin{x}+\cos{x}} + C \\
\end {align*} $$
