How to solve instability in ODE problem?

Yeah, don’t do that. The only reason why your MATLAB code even works is because this does not do what you expect in MATLAB and it actually ignores this. We don’t ignore your changes, so it will cause bad things. See: