Why does ODE15s return negative states despite setting 'NonNegative' option?

Dear MatLab community,
I am trying to solve a stiff ODE system of 10 equations using ODE15s. Due to some root expressions in the equations and thus imaginary numbers if some of the states turn negative, the 'NonNegative' option is used in the ODE options. However, this does not work i.e. states turn negative, I get imaginary numbers and the calculation fails. If, on the contrary, I set the states manually to positive values
(with something like: "if x(i) < 0 x(i) = 1e-30; end")
within my function containing the ODE system it works and the states do not turn negative. I read that ODE15s ignores the 'NonNegative' option if there is a mass matrix but I am dealing with ODEs only. Unfortunately, I cannot provide any code here and the problem seems to arise only for my complex system. I tried reduced models without running into those kind of problems. Does anybody have an idea why 'NonNegative' does not work?
Thank you!

5 件のコメント

Steven Lord
Steven Lord 2015 年 9 月 23 日
Show how you constructed your options structure (so we can be sure you created it correctly) and show your call to ODE15S (so we can be sure you passed the options structure into it in the correct position.)
Giorgios
Giorgios 2015 年 9 月 24 日
Hi Steven, here are the options structure and ODE15s call:
options = odeset('RelTol',1e-14,'AbsTol',1e-14,'NonNegative',[1:10]);
[t, x] = ode15s(@ABC_DGL, tspan, x0, options, p);
I also tried setting the tolerances to even higher levels without success unless I use the work-around described above. Thanks for any ideas!
John Barrett
John Barrett 2018 年 3 月 30 日
Hi Giorgios and Steven,
Did you guys ever come up with an answer to this question? I'm also seeing negative values in my ode15s output despite using the 'NonNegative' setting.
Thanks, John Barrett
Varun Kothamachu
Varun Kothamachu 2018 年 7 月 4 日
編集済み: Varun Kothamachu 2018 年 7 月 4 日
Hi,
Is there an update to this question. I am in a similar situation, and would like know if you you found a fix. thanks, Varun
Lucademicus
Lucademicus 2018 年 10 月 29 日
The same goes for me; ODE15s results in some negative values despite setting the NonNegative name-value pair within odeset (which I give as options to ODE15s). As the negative result is really small (~-1E-12), I suspect that this can be overcome by tuning the sensitivities/tolerances of the solver.

サインインしてコメントする。

回答 (1 件)

Thomas Hay
Thomas Hay 2018 年 11 月 16 日

1 投票

The NonNegative option keeps the ODE solver from accepting negative values for the selected variables. If negative values are calculated the solver will reduce the timestep and calculate the step again. It does however not prevent the ODE solver from evaluating the function with negative values for the selected variables while the result for a step is calculated, causing the integration to fail if the evaluated function cannot handle negative values. The only solution I have found so far is to manually set negative values to zero within my function to keep it from returning imaginary numbers which is pretty much what Giorgios described. Reducing tolerances and maximum timestep may help as well as it can prevent the solver from predicting negative value when the slope changes steeply only when a value gets very close to zero. So in short even with the NonNegative option selected your function needs to be able to handle negative values to prevent the integration from failing as the ODE solver will only prevent the accepted results from containing negative values. (I am using ODE15s and at least for that solver this appears to be the case, I have not looked at the other ODE solvers in detail)

カテゴリ

質問済み:

2015 年 9 月 23 日

回答済み:

2018 年 11 月 16 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by