TITLE: Integrate $\int\frac{\cos^2(x)-x^2\sin(x)}{(x+\cos(x))^2}dx$
QUESTION [6 upvotes]: I had to integrate the following integral:
\begin{equation}
\int\frac{\cos^2(x)-x^2\sin(x)}{(x+\cos(x))^2}dx
\end{equation}
but I can't find a suitable substitution to find a solution. Nothing I try works out and only seems to make it more complicated. Does anyone have an idea as to how to solve this?
I also tried to get help from WolframAlpha but it just says that there is no step-by-step solution available. 
The sollution by wolfram alpha is:
\begin{equation}
\int\frac{\cos^2(x)-x^2\sin(x)}{(x+\cos(x))^2}dx = \frac{x\cos(x)}{x+\cos(x)} + c
\end{equation}

REPLY [4 votes]: When you see an integral like that, although you quickly find $u=x+\cos x$ won't work, you can't help but think there'll be a nice antiderivative of the form $\frac{f}{x+\cos x}$. So now, we want to solve $$\cos^2x-x^2\sin x=(x+\cos x)f^\prime-(1-\sin x)f.$$Can we write the left-hand side as a linear combination of $x+\cos x,\,1-\sin x$? After a little experimenting, yes: it's $$x\cos x-x^2\sin x+\cos^2x-x\cos x\sin x-x\cos x+x\cos x\sin x\\=(x+\cos x)(\cos x-x\sin x)-x\cos x(1-\sin x),$$implying the choice $f=x\cos x,\,f^\prime=\cos x-x\sin x$, which happily are consistent.