<s>[INST] how can i evaluate this indefinite-integral? $$\int \frac{x^2}{(x\cos{x}-\sin{x})^2} dx$$
I tried to turn it to $\tan$ and $\sec$ but it didn't work out very well. How can I evaluate this indefinite integral using regular methods?
 [/INST] $\bf{My\; Solution::}$ Given $\displaystyle \int\frac{x^2}{(x\cos x-\sin x)^2}dx$
we can write $\displaystyle (x\cos x-\sin x) = \sqrt{1+x^2}\left(\frac{x}{\sqrt{1+x^2}}\cdot \cos x - \frac{1}{\sqrt{x}}\cdot \sin x\right) = \sqrt{1+x^2}\cdot \cos (x+\phi)$
where $\displaystyle \cos \phi = \frac{x}{\sqrt{1+x^2}}$ and $\displaystyle \sin \phi = \frac{1}{\sqrt{1+x^2}}$. So we get  $\;\; \cot \phi = x\Rightarrow \phi = \cot^{-1}(x)$
So Integral convert into $\displaystyle \int \frac{x^2}{(1+x^2)\cdot \cos^2 \left(x+\phi\right)}dx = \int \sec^2(x+\phi)\cdot \frac{x^2}{1+x^2}dx$
$\displaystyle = \int\sec^2\left(x+\cot^{-1}(x)\right)\cdot \frac{x^2}{1+x^2}dx$
Now Let $(x+\cot^{-1}(x)) = u$, Then $\displaystyle \left(1-\frac{1}{1+x^2}\right)dx = du\Rightarrow \frac{x^2}{1+x^2}dx = du$
So Integral convert into $\displaystyle \int \sec^2(u)du = \tan (u)+\mathbb{C}$
So we get $\displaystyle = \tan \left(x+\cot^{-1}(x)\right)+\mathbb{C} = \tan \left(\frac{\pi}{2}+x-\tan^{-1}(x)\right)+\mathbb{C}$
$\displaystyle  = -\cot(x-\tan^{-1}(x)) = -\frac{1}{\tan(x-\tan^{-1}(x))}+\mathbb{C} = -\left(\frac{1+\tan (x)\cdot x }{\tan (x)-x}\right)+\mathbb{C}$
So $\displaystyle \int \frac{x^2}{(x\cos x-\sin x)^2}dx = \left(\frac{\cos x +x\cdot \sin x}{x\cdot \cos x-\sin x}\right)+\mathbb{C}$
</s>