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

9 visualizaciones (últimos 30 días)
Giorgios
Giorgios el 23 de Sept. de 2015
Respondida: Thomas Hay el 16 de Nov. de 2018
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 comentarios
Varun Kothamachu
Varun Kothamachu el 4 de Jul. de 2018
Editada: Varun Kothamachu el 4 de Jul. de 2018
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 el 29 de Oct. de 2018
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.

Iniciar sesión para comentar.

Respuestas (1)

Thomas Hay
Thomas Hay el 16 de Nov. de 2018
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)

Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by