Advice on integrating $\int \frac{x^2 +n(n-1)}{(x \sin x +n \cos x)^2} dx$ Our integral is:
$$\int \frac{x^2 +n(n-1)}{(x \sin x + n\cos x)^2} dx$$
I considered that this can be turned into some sort of quotient differential:
$$ d \frac{u}{v} = \frac{ v du - u dv}{v^2}$$
Now, comparing this with our integral:
$$ v = x \sin x + \cos x$$
And,
$$ dv = \sin x + x \cos x - n \sin x = (1-n) \sin x + x \cos x$$
Now the problem is I can't figure out $u$ / make the numerator of the form $ vdu - u dv$... what do I do next?
 A: Instead of looking for a function $u$ such that the integrand is the derivative of the quotient of two functions, I will present a different approach.
\begin{align*}
\int \frac{x^2 +n(n-1)}{(x \sin x + n\cos x)^2} \; \mathrm{d}x &= \int \frac{x^2 +n(n-1)}{\left(\sqrt{x^2+n^2} \cos \left(x-\arctan{\left(\frac{x}{n}\right)}\right)\right)^2} \; \mathrm{d}x \tag{1}\\
&=\underbrace{\int \frac{x^2 +n(n-1)}{\left(x^2+n^2\right) \cos^2 \left(x-\arctan{\left(\frac{x}{n}\right)}\right)} \; \mathrm{d}x}_{t=x-\arctan{\left(\frac{x}{n}\right)}}\\
&= \int \frac{x^2 +n(n-1)}{\left(x^2+n^2\right) \cos^2 \left(t\right)} \; \left(\frac{x^2+n^2}{x^2+n(n-1)}\; \mathrm{d}t\right) \\
&= \int \sec^2{t} \; \mathrm{d}t \\
&= \tan{t}+C \\
&= \tan{\left(x-\arctan{\left(\frac{x}{n}\right)}\right)}+\mathrm{C} \\
&= \frac{n \sin{x}-x\cos{x}}{n\cos{x}+x\sin{x}}+\mathrm{C} \\
\end{align*}

$(1)$: $\mathrm{A}\sin{x}+\mathrm{B}\cos{x}=\sqrt{\mathrm{A}^2+\mathrm{B}^2}\cos{\left(x-\arctan{\left(\frac{\mathrm{A}}{\mathrm{B}}\right)}\right)}$
A: $$I=\int \frac{x^2+n(n-1)}{(x\sin x+n \cos x)^2} dx$$
Multiply up and down by $x^{2n-2} \cos x$, then
$$I=\int \frac{(x^2+n(n-1))x^{2n-2} \cos x dx}{(x^n \sin x+n x^{n-1} \cos x)^2 \cos x}$$
Let $$(x^n \sin x+n x^{n-1} \cos x)=t \implies x^{n-2} \cos x(x^2+n(n-1)) dx=dt$$
$$\implies I=\int \frac{(x^2+n(n-1))x^{n-2} \cos x }{(x^n \sin x+n x^{n-1} \cos x)^2} x^n \sec x dx$$
Do integration by part taking $x^n \sec x$ as first and remaining as second function, then
$$I=-\frac{x \sec x}{(x\sin x+n \cos x)}+\int \sec^2 x dx$$
$$I=-\frac{x \sec x}{x \sin x+ n \cos x)}+\tan x+C$$
