<s>[INST] An indefinite Integral Problem with algebric numerator and trigonometric denominator $$\int \frac{x^2+(n(n-1))}{(x\sin x +n\cos x)^2 } dx$$
I know this is an homework problem, but I really couldn't think of any way to solve it. Like DI Method (No go) , What kind of substitution as denominator is trigonometric whereas Numerator is algebric. Thought of n(n-1) can come by double differentiating but.. like how would we have it here ... etc confusing and weird thoughts. Please help me out
 [/INST] $I = \int\frac{x^2 + n(n-1)}{(x\sin x + n\cos x )^2}dx$
Now we'll try to convert it into the form of $\frac{a}{y} +  \frac{b}{y^2}$, where $a,b$ are functions of $x$ and $y$ is the denominator.
$$x^2+n(n-1) =(x\sin x + (n-1)\cos x)(x\sin x+n\cos x)-((1-n)\sin x + x\cos x)(n\sin x - x\cos x)$$ 
$$$$
$I = \int \big[\frac{(x\sin x + (n-1)\cos x)(x\sin x+n\cos x)}{(x\sin x + n\cos x )^2} - \frac{((1-n)\sin x + x\cos x)(n\sin x - x\cos x)}{(x\sin x + n\cos x )^2}\big]dx$
Now,
$I = \int\big[\frac{(x\sin x + (n-1)\cos x)}{(x\sin x + n\cos x )} - \frac{((1-n)\sin x + x\cos x)(n\sin x - x\cos x)}{(x\sin x + n\cos x )^2}\big]dx$
Let $I_1 = \int\frac{(x\sin x + (n-1)\cos x)}{(x\sin x + n\cos x )}dx$ , $I_2 = \frac{((1-n)\sin x + x\cos x)(n\sin x - x\cos x)}{(x\sin x + n\cos x )^2}dx$

In $I_2$,
let $u = n\sin x - x\cos x$, $dv = \frac{(1-n)\sin x + x\cos x}{(x\sin x + n\cos x )^2}dx$
$du = (n\cos x - \cos x + x\sin x)dx$ , 
[In $v$ , $t = x\sin x + n\cos x$, $dt = (x\cos x + \sin x - n\sin x )dx = (x\cos x + (1-n)\sin x)dx$]
$v = \int\frac{(1-n)\sin x + x\cos x}{(x\sin x + n\cos x )^2}dx = \int\frac{dt}{t^2} = -\frac{1}{t} = - \frac{1}{x\sin x + n\cos x}$

So, 
$I_2 = uv - \int vdu = -(n\sin x - x\cos x)\frac{1}{x\sin x + n\cos x} + \int (n\cos x - \cos x + x\sin x).\frac{1}{x\sin x + n\cos x}dx + c$
$I_2 = - \frac{n\sin x - x\cos x}{x\sin x + n\cos x} + \int \frac{x\sin x + (n-1)\cos x}{x\sin x + n\cos x}dx +c$
$I_2 = - \frac{n\sin x - x\cos x}{x\sin x + n\cos x} + I_1 +c $
$$I = I_1 - I_2 = \frac{n\sin x - x\cos x}{x\sin x + n\cos x} + k$$
($k = -c$)
</s>