<s>[INST] How to calculate $\int{\frac {x^2}{ ( x\cos x -\sin x ) ^2}}\,{\rm d}x$? When I want to calculate
$$\int{\frac {x^2}{ ( x\cos x -\sin x ) ^2}}\,{\rm d}x$$
I have tested with software and get
$${\frac {x\sin \left( x \right) +\cos \left( x \right) }{x\cos \left( x
 \right) -\sin \left( x \right) }}$$
But I can not come to this conclusion, neither using integration by parts, nor using trigonometric identities, nor multiplying by their conjugate, Even by rational trigonometric substitution. I do not know what else to try. Could you give me any suggestions?
 [/INST] We can tackle the integral by integration by parts as below:
$$
\begin{aligned}
& \int \frac{x^{2}}{(x \cos x-\sin x)^{2}} d x \\
=& \int \frac{x}{\sin x} d\left(\frac{1}{x \cos x-\sin x}\right) \\
=& \frac{x}{\sin x(x \cos x-\sin x)} -\int \frac{1}{x \cos x-\sin x} \cdot \frac{\sin x-x \cos x}{\sin ^2x}dx\\=& \frac{x}{\sin x(x \cos x-\sin x)} +\int \csc ^{2} x d x \\
=& \frac{x}{\sin x(x \cos x-\sin x)}-\cot x+C\\=& \frac{x \sin x+\cos x}{x \cos x-\sin x}+C
\end{aligned}
$$
</s>