# Solution to Nonlinear ODE differs from textbook

Trying to work backward to the solution for this nonlinear ODE in a control book I have:

$$\frac{\mathrm{dx} }{\mathrm{d} t}=-x+x^2$$

Book lists the solution to the ODE as:

$$x(t)=\frac{x_0e^-t}{1-x_0+x_0e^-t}$$

I used the ODE45 function in MATLAB to generate a solution from a family of initial conditions and I get the same plot as in the book.

I run into issues when I try to analytically solve this equation through separation of variables:

$$\int \frac{dx}{-x+x^2}=\int dt$$

$$ln\left|\frac{x+1}{x} \right|=t+C$$

Add my initial conditions

$$ln\left|\frac{x+1}{x} \right|=t+ln\left|\frac{x_0+1}{x_0}\right|$$

Multiply both sides by e

$$\frac{x+1}{x}=e^t\left ( \frac{x_0+1}{x_0} \right )$$

Rearrange

$$x=\frac{1}{e^t\left ( \frac{x_0+1}{x_0} \right )-1}$$

I use dsolve on Matlab to try come up with a general solution and I get almost the same as I worked by hand:

However, it does not match the plot from the textbook.

Unsure where I am going wrong. Can someone review my working.

• From $\int \frac{dx}{x(-1+x)}$ you can not get a factor $(x+1)$ in the integral. Commented Apr 20, 2023 at 10:13
• Thank you @LutzLehmann and Goncalo
– SS1
Commented Apr 20, 2023 at 10:19
• It is in the end simpler to treat this as Bernoulli equation, that is, divide by $-x^2$ and get a linear DE. Commented Apr 20, 2023 at 10:32