stiff ode solver with non-negative properties

6 views (last 30 days)
Xinyue Liang
Xinyue Liang on 12 Sep 2022
Edited: Torsten on 12 Sep 2022
I looking to construct a model consisting of differential equations solved numerically using matlab. The results of the equations are pretty stiff, so only a stiff solver works. I am also hoping for the results to be set as non-negative to better match the empirical data. This does not seem to work with the standard ode solvers. Do you have any recommendations for this situation?

Answers (1)

Torsten
Torsten on 12 Sep 2022
Edited: Torsten on 12 Sep 2022
Do the negative solutions result from numerical inaccuracies or from the equations themselves ?
If the latter is the case, no recommendations can be given because the solution is determined by the ODEs and the initial conditions. If they turn out to be negative, then you must accept this.
Else try the NonNegative option in the ODE solver options (together with a stiff solver, e.g. ODE15S).
  2 Comments
Torsten
Torsten on 12 Sep 2022
@Xinyue Liang comment moved here:
I think it results from numerical inaccuracies. The NonNegative option for the ODE solver does not seem to work for any of the stiff solvers (ode15, ode23). Is there another way to change this or maybe alter the equations to manually set it to be non-negative? Thank you so much!
Torsten
Torsten on 12 Sep 2022
Edited: Torsten on 12 Sep 2022
If the NonNegative option does not work usually indicates that the negative values stem from the equations themselves, not from numerical inaccuracies...
Before working with the variables, you could check them for nonnegativity in an if-statement and reset them to a small positive value if they are negative. But this only works if they are really negative due to numerical inaccuracies. Otherwise, you will get unexpected solutions or the solver will quit.

Sign in to comment.

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!