How to limit the range of a parameter in Simbiology?

3 views (last 30 days)
For example, I have a variable BMI which is defined as a rule:
BMI = normrnd(22,3.5);
and I want to limit the output values between 18 and 30, how do I do that?
I tried using events tab to do that, but it doesn't work for parameters, works only for species.

Accepted Answer

Arthur Goldsipe
Arthur Goldsipe on 19 Feb 2014
Hi Rajith,
You're calling normrnd in an initial assignment rule, right? I would be very careful using random numbers in the middle of a SimBiology simulation, because it could make it very hard to solve the model accurately.
Assuming you're talking about using initial assignment rules to set the value of a parameter, I would probably enforce the bounds inside of the rule itself. One approach is to use min and max:
BMI = max(18, min(30, normrnd(22,3.5)));
Another approach would be to take advantage of MATLAB's new probability distribution objects (assuming you have a relatively recent version of MATLAB, specifically R2013a or later):
BMI = prob.NormalDistribution(22,3.5).truncate(18,30).random()
By the way, you can use events to modify parameters, but you have to make sure the parameter is not marked "Constant". However, you cannot use events to modify the initial value of a parameter or species, because events cannot be triggered at time=0.
-Arthur

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!