For an ODE like this:$(1-y)y'+y^2=0$ with the initial condition $y(1)=1$, how to solve it numerically? I know this equation can be solved analytically by DSolve
. In fact, my equation is more complicated than this, I have to solve it numerically. Using NDSolve
directly,
NDSolve[{(1 - y[x])*y'[x] + y[x]^2 == 0, y[1] == 1}, y, {x, 1, 5}]
it will display error messages:
Power::infy: Infinite expression 1/0. encountered.
NDSolve::ndnum: Encountered non-numerical value for a derivative at x == 1.`.
I guess this problem happens because the initial condition just makes the coefficient of y'[x]
be zero. So my question is how to overcome this problem?
NDSolve[{(1 - y[x])*y'[x] + y[x]^2 == 0, y[1] == 1.01}, y, {x, 1, 5}]
$\endgroup$