I'm trying to solve a set of ODEs with a Heaviside step function which depends on the sign of the derivative of the function.
This is a simplifying example of what I'm trying to do
sol = NDSolve[{
x'[t] == (0.1 x[t]^3 - x[t]) HeavisideTheta[x'[t]],
x[0] == -2}, {x}, {t, 0, 1}];
Plot[Evaluate[x[t]] /. sol, {t, 0, 10}]
I get a lot of errors (NDSolve::tddisc
, NDSolve::ntdvdae
, NDSolve::nlnum
), and it seems that it is not the proper way to work with NDSolve
.
Can anyone please advise on how to properly use the Heaviside function inside NDSolve
?
UnitStep
instead. $\endgroup$ – AccidentalFourierTransform Oct 23 '18 at 19:30Heaviside -> UnitStep
does not help for me (V11.3). In both cases I get a solution -- is the solution correct? I think so. It's impossible to solve forx'[t]
, I think, which makes it a DAE, whichNDSolve
can solve. This equivalent:NDSolve[{x'[t] == Clip[0.1 x[t]^3 - x[t], {0, Infinity}], x[0] == -1/2}, {x}, {t, 0, 1}]
but emits no warnings or errors. $\endgroup$ – Michael E2 Oct 24 '18 at 0:41x
inPlot
as you use inNDSolve
$\endgroup$ – Bill Watts Oct 24 '18 at 7:46x'[t]
$\endgroup$ – Bill Watts Oct 24 '18 at 7:48