different event functions for the same species

Hi,
I developed a model in Simbiology in which Fw is a parameter as a function of mass. The mass varies with time.
I want to set two events as follows:
Trigger: mass>=Threshold_mass
event function: Fw = 0.1* mass
Trigger: mass<Threshold_mass
event function: Fw = 0.0003* mass
I received this error message:
"Invalid repeatedAssignment rule 'Rule_20'. The variable 'Fw_T' is also used by an event function.\n"
Could you please suggest any idea that may help?
Thanks

3 Comments

Hi,
I have no knowledge about the SimBiology Toolbox. But as per my guess ,the 'equal to' case might be creating the problem. For both the triggers mass=Threshold_mass holds.
I would suggest you to remve the equal to operator from any of the trigger.
We need Arthur Goldsipe here :-)
@Mann Baidi thank you for your note. I wrote here the second = by mistake.

Sign in to comment.

 Accepted Answer

Arthur Goldsipe
Arthur Goldsipe on 30 Apr 2024
Edited: Arthur Goldsipe on 30 Apr 2024
The problem is that you have two conflicting mathematical definitions of Fw. You are trying to set it with both a repeated assignment rule (which applies at all times during a simulation) and with an event (which modifies Fw when a condition is met). What is your intent? Perhaps you only meant for the rule to apply at time 0, in which case you should change it to an initial assignment. Then you can set it with an event at later times.

6 Comments

I did that. As I said, Fw is is a function of mass and the mass changes with time. When I set the first equation as an initial assignment, Fw had a fixed value and this is not true as it should vary with time.
Fw is the absorption fraction of a drug and it varies with the mass of the tissue. I want my model to switch between these two functions during the simulation as the mass gets larger or lower than the threshold during the treatment.
Do you have any suggestions @Arthur Goldsipe?
Let me first make sure I understand what you want to do. I believe you want Fw to be calculated at every time step of the simulation, but you want to use two different equations (that differ only in the value of a constant) depending on the mass. If that is correct, then my suggestion would be to parameterize that constant and use the event to modify this constant. Then, you will only expression that defines the value of Fw at all simulation times. More specifically:
  • Add a new parameter to your model, and set the Constant property to false (so that you can change its value with an event). Let's say you call this parmeter k.
  • Update your repeated assignment for Fw to be "Fw = k*mass".
  • Update the event functions to "k = 0.1" and "k = 0.0003".
Brillient! thank you.
Oh, and one other comment. I do not recommend modeling this without an event (for example, by adding a repeated assignment of the form "Fw = mass*(0.1*(mass>=Threshold_mass) + 0.0003*(mass<Threshold_mass))". Any time you have a discontinuity in your equations, you really want to use an event to make sure that the ODE solver detects that discontinuity and resets its internal solver state apropriately. If you don't use an event, I've seen various "bad things" happen: You might get an ODE solver error, a "solution" that doesn't capture the discontinuity, or an inaccurate solution.
Torsten
Torsten on 30 Apr 2024
Edited: Torsten on 30 Apr 2024
Often, packages are that encapsulated that they lack the necessary flexibility for special requests. I don't know SimBiology, but there might be situations (not in this case) when a "quick-and-dirty" solution is better than no solution.
In case an ode solver would have been used directly for the above case, the event I would have chosen is when mass - Threshold_mass = 0 with a reset of Fw and restart after this event had happened. For me, this solution seems more natural than yours. But as said: since we are in the straitjacket of SimBiology, the internal possible options have to be respected.
@Torsten you make a good point. I'll keep thinking about how we can loosen this stratjacket we find ourselves in. :-)

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2024a

Community Treasure Hunt

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

Start Hunting!