dy/dx = (y+x^2-2)/(x+1) implies
dy/dx - y/(x+1) = (x^2-2)/(x+1)
This is a linear first order differential equation of the form
dy/dx+P(x)y = Q(x)
where P(x) = -1/(x+1) and Q(x)=(x^2-2)/(x+1). It is well known that such an equation admits of an integrating factor given by
exp(int P(x) dx) = exp(-int dx/(x+1)) = exp(-ln(x+1)) = 1/(x+1)
Multiplying both sides of the equation by this factor gives us
1/(x+1) dy/dx - y/(x+1)^2 = (x^2-2)/(x+1)^2
Now, the left hand side is
1/(x+1) dy/dx + d/dx( 1/(x+1)) y = d/dx(y/(x+1))
On the other hand
(x^2-2)/(x+1)^2 = (x^2color(red)(+2x+1)color(blue)(-2x-1)-2)/(x+1)^2
qquad = ((x+1)^2-2(x+1)-1)/(x+1)^2 = 1-2/(x+1)-1/(x+1)^2
Thus, the equation becomes
d/dx(y/(x+1)) = 1-2/(x+1)-1/(x+1)^2
Integration with respect to x yields
y/(x+1) = x-2ln|x+1|+1/(x+1)+C
The constant of integration C can be determined by using the initial condition y(0) = 2 :
2/(color(red)0+1) = color(red)0-2ln|color(red)0+1|+1/(color(red)0+1)+C implies C=1
Thus, the solution is
y/(x+1) = x-2ln|x+1|+1/(x+1)+1
or
y(x) = (x+1)^2-2(x+1)ln|x+1|+1