dgaragones
(David G. Aragonés)
1
Is there any Mathematica option equivalent to Nonnegative in odeset in Matlab?
Here is the documentation about the function Im talking about:
https://www.mathworks.com/help/matlab/math/nonnegative-ode-solution.html
I think its a very useful function and itd be nice to have something similar in Mathematica.
Thanks in advance!
You may try with WhenEvent. For example, this gives a solution which becomes negative:
NDSolveValue[{y'[x] == Sqrt[Abs[y[x]]], y[1] == 1}, y, {x, -5, 3}]
but we can pick the nonnegative solution with this:
NDSolveValue[{y'[x] == Sqrt[Abs[y[x]]], y[1] == 1,
WhenEvent[y[x] < 0, y[x] -> 0]},
y, {x, -5, 1}]
dgaragones
(David G. Aragonés)
3
Thanks for your answer!
Could this technique be applied to a vector variable?