Reaction continues even after the concentration is below zero in Simbiology

8 views (last 30 days)
Hello,
I am trying to simulate a simple reaction model in Simbiology but met a problem that the system would let concentration reach negative.
As reagent (A) is consumed in the reaction, its concentration would decrease with time, however with enough time, Simbiology would let this concentration go negative. Is there a way that reaction could be stopped after all reagent is used up? In anothoer word, once A=0 the reaction won't go beyond from that point as time continues (all the reagent and product will reach balance and not change any more).
The idea is similar to add an "if (A<=0) A=0" judgement but I do not know how to do it in simbiology. I tried to add "A=max(A,0)" in repeated assignment but it won't work. Thinking about event trigger too but it seems Event could only work at the first time of triggering.
Thank you in advance

Accepted Answer

Arthur Goldsipe
Arthur Goldsipe on 2 May 2022
I answered a similar question here. As I mention there, there's currently no way to completely prevent negative numbers in all cases. But it's generally safe to ignore small negative values small (relative to your specified solver tolerances). If the magnitude of the negative numbers is large, it could indicate a modeling error and/or a problem with solver tolerances. If you see such negative numbers, you should try to understand what is causing them and make an appropriate change to your model. If there is some sort of feedback that causes negative numbers to get mangified, you may need to modify the expression for the reaction rate. For example, if X is a species that is negative, you might want to replace occurences of X in rate expression with max(0,X). I would recommend this over trying to use an event or repeated assignment rule.
  3 Comments
W Y
W Y on 3 May 2022
Edited: W Y on 3 May 2022
Thanks Arthur! I have read that link before posting this question and understood it was about the tolerance to deal with a tiny calculated amount less than 0. For my question, your suggestion regarding editing the rate expression is very helpful. Now the model is working.
W Y
W Y on 3 May 2022
To jeremy, that debugger seems also very useful. Will check that out. Thank you

Sign in to comment.

More Answers (2)

Achal Mahajan
Achal Mahajan on 2 May 2022
Hi,
This post might be useful https://www.mathworks.com/matlabcentral/answers/78266-non-negative-values-for-species-in-simbiology. The same problem has been discussed in detail. Feel free to reach out again if it does not work for you!
  1 Comment
W Y
W Y on 3 May 2022
Thank you for your timely reply. Before I posted this question, I have read that post seveal times. It mainly deals with the problem when there is a calculation result close to Zero (tiny amount less than 0). In that case, we can set tolerances to let the program know when that should be treated as Zero, which is not my question here. The other solution solves the problem but I really appreacite your input.

Sign in to comment.


Torsten
Torsten on 2 May 2022
If the reaction rate of A is proportional to A (as it should be), you usually don't get problems with negative concentrations.

Communities

More Answers in the  SimBiology Community

Categories

Find more on Extend Modeling Environment in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!