Struggling with ODE Falling Chain I am having difficulties with another differential equations problem which is as follows
$$xu\frac{du}{dx} + u^2 = gx$$
We are told that this ODE models a chain sliding off a friction less table g is acceleration due to gravity, x is the length of chain hanging off the table and u is the velocity of the chain. The question is asking to solve the differential equation and find the velocity of the chain when it falls completely off the table.
My first approach to the problem was to first attempt to manipulate the equation into something that looked like a linear equation by dividing through by xu
$$\frac{du}{dx} + \frac{u}{x} = \frac{g}{u}$$
I then proceeded to find the integrating factor which I said was $$e^\int ln(x)$$ which simplifies to just x and then went about solving the DE using this method and ended up with the final equation $$u = \frac{gx}{2u} + c$$ which I do not believe to be the correct answer I tried coming up with some initial conditions with the given information but I believe my answer to be incorrect.
I have consulted other websites and notes and found an answer on many websites is $$v_f =(\frac{g}{a}(a^2-b^2))^\frac{1}{2}$$ however I am unsure how this equation is derived or even if it is relevant to my problem.
Thank you for any help or feed.
 A: You made a mistake when you integrated after using the integrating factor). That step isn't valid because $u$ appears on both sides of the equation. Instead, let $w = u^2$. Then $$\frac{dw}{dx} = 2u \frac{du}{dx}.$$ But from the equation $$u \frac{du}{dx} = - \frac{u^2}{x} + g = -\frac w x +g.$$ Then $$\frac{dw}{dx} = -\frac{2w} x + 2g \,\,\,\ \implies \,\,\, \frac{dw}{dx} + \frac{2w}{x} = 2g.$$ Multiplying through by $x^2$ gives $$x^2 \frac{dw}{dx} + 2x w = 2gx^2 \,\,\, \implies \,\,\, \frac d{dx}\left[x^2 w \right] = 2gx^2.$$ Then $$x^2w = \frac{2gx^3}{3} + C \,\,\, \implies \,\,\, w(x) = \frac{2gx}{3} + \frac C{x^2}.$$ Taking the square root gives $$u(x) = \sqrt{\frac{2gx}{3} + \frac C{x^2}}.$$ Next you need to solve for $C$ using some sort of condition on $u$. Then to find the falling velocity, take the derivative of $u$ and plug in the $x$ which corresponds to $u$ falling completely off the table. 
A: $$xu(x)u'(x)+u(x)^2=gx\Longleftrightarrow u(x)^2+xu(x)u'(x)=gx\Longleftrightarrow$$
$$2u'(x)u(x)+\frac{2u(x)^2}{x}=2g\Longleftrightarrow$$

Let $r(x)=u(x)^2$ which gives $r'(x)=2u(x)u'(x)$:

$$r'(x)+\frac{2r(x)}{x}=2g\Longleftrightarrow$$

Let $v(x)=\exp\left[\int\frac{2}{x}\space\text{d}x\right]=x^2$.
Multiply both sides by $v(x)$:

$$x^2r'(x)+2xr(x)=2gx^2\Longleftrightarrow$$

Substitute $2x=\frac{\text{d}}{\text{d}x}\left(x^2\right)$:

$$x^2r'(x)+\frac{\text{d}}{\text{d}x}\left(x^2\right)\cdot r(x)=2gx^2\Longleftrightarrow$$

Apply the reverse product rule to the left-hand side:

$$\frac{\text{d}}{\text{d}x}\left(x^2r(x)\right)=2gx^2\Longleftrightarrow\int\frac{\text{d}}{\text{d}x}\left(x^2r(x)\right)\space\text{d}x=\int2gx^2\space\text{d}x\Longleftrightarrow$$
$$x^2r(x)=\frac{2gx^3}{3}+\text{C}\Longleftrightarrow r(x)=\frac{\frac{2gx^3}{3}+\text{C}}{x^2}\Longleftrightarrow$$
$$u(x)^2=\frac{\frac{2gx^3}{3}+\text{C}}{x^2}\Longleftrightarrow u(x)=\pm\sqrt{\frac{\frac{2gx^3}{3}+\text{C}}{x^2}}\Longleftrightarrow u(x)=\pm\frac{\sqrt{\text{C}+2gx^3}}{x\sqrt{3}}$$
