Integrate $\int\frac{\cos^2(x)-x^2\sin(x)}{(x+\cos(x))^2}dx$

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}$$

• But what is the solution by WolframAlpha? – Dr. Sonnhard Graubner Jan 18 at 16:57
• I've included the solution by WolframAlpha in the question. – Viktor Jan 18 at 17:00

$$\begin{equation} \int\frac{\cos^2 x-x^2\sin x }{(x+\cos x)^2}dx \end{equation}$$
Divide both numerator and denominator by $$x^2\cos^2 x$$
$$\begin{equation} \int\frac{\cos^2 x-x^2\sin x }{(x+\cos x)^2}dx =\int\frac{\dfrac{1}{x^2}-\dfrac{\sin x}{\cos^2 x}}{(\dfrac{1}{\cos x}+\dfrac{1}{x})^2}dx =\frac{1}{\dfrac{1}{\cos x}+\dfrac{1}{x}} + C =\frac{x\cos x}{x + \cos x} + C \end{equation}$$
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.
• What you are indeed doing is applying the quotient rule in reverse. Namely $$\left (\frac{u}{v} \right )' = \frac{u' v - v' u}{v^2}$$ and is a nice little trick provided the conjuring up of the function $u(x)$ is not too difficult. – omegadot Jan 19 at 1:23
Note that the derivative of $$x + \cos(x)$$ in the denominator is $$1-\sin(x)$$ . We can try to make this term appear in the numerator and then integrate by parts. We have $$\frac{\cos^2(x)-x^2\sin(x)}{(x+\cos(x))^2} = \frac{\cos^2(x) - x^2 + x^2(1-\sin(x))}{(x+\cos(x))^2} = \frac{\cos(x) - x}{x+\cos(x)} + x^2 \frac{1-\sin(x)}{(x+\cos(x))^2} \, ,$$ so \begin{align} \int \frac{\cos^2(x)-x^2\sin(x)}{(x+\cos(x))^2} \, \mathrm{d}x &= \int \frac{\cos(x) - x}{x+\cos(x)} \, \mathrm{d} x - \frac{x^2}{x+\cos(x)} + \int \, \frac{2 x}{x+\cos(x)}\mathrm{d} x \\ &= x - \frac{x^2}{x+\cos(x)} = \frac{x \cos(x)}{x+\cos(x)} \end{align} as desired.