Also, I can't make everything dimensionless because that would mess up the rest of the model. Any suggestions would be appreciated!
What is wrong with the 'max' function in Simbiology?
6 views (last 30 days)
Show older comments
tash7827
on 8 Aug 2016
Commented: Walter Roberson
on 8 Aug 2016
Hi, I am having issues with correctly defining a rule (repeated assignment) for a block (parameter). The rule follows:
[Dynamic Glucagon Secr] = kGSRd*max((-[Plasma Glu]/Vg),0)
This is the only warning that I get:
"Cannot perform dimensional analysis for rule 'Dynamic Glucagon Secr rule' because of the function 'max' in the rule. Because UnitConversion is on,
correct simulation results will depend on this expression being dimensionally correct. Additionally, SimBiology simulates the model in a unit system
determined at runtime. The units are determined by the units used in the model and the model's configset. Unless the inputs and outputs to the function
are dimensionless, results may change due to configset option changes, changes to the model, or version changes in SimBiology. It is recommended that
input and output arguments to functions be dimensionless to ensure correct results."
Why can't I use the 'max' function? And are there any good alternatives?
4 Comments
Ingrid Tigges
on 8 Aug 2016
I have not checked this in SimBiology myself but have you thought of defining a variable with the same units as [Plasma Glu]/Vg ? Does it work then? How are the variables in the expression (-[Plasma Glu]/Vg) defined? Is Vg a positive constant and Plasma Glu is the concentration in plasma? If this is true, shouldn't the expression not be always negative?
Accepted Answer
Walter Roberson
on 8 Aug 2016
My interpretation would be that it is not an issue with max() specifically, but instead is an issue with invoking any MATLAB function passing in data with units. When you call a MATLAB function, only the numeric values associated with a measurement can be passed in, and not the units, and no units can be returned from the MATLAB function. In general, when you call a MATLAB function the units of the output are not necessarily the same as the units on the input, but SimBiology cannot analyze into the MATLAB function, so SimBiology cannot check to see if the units are correct.
For example you might have defined a MATLAB function that took a temperature and did (T*9/5+32) which is an implicit C to F units conversion (and which might be the wrong conversion since the temperature might not be in Celsius in the first place, since the units for temperatures are not determined until run time.) The best SimBiology could do in such a case would be to assume that the output was the same unit as the input, which might be acceptable in your case but would not be acceptable in the temperature example I give here.
As a further point: suppose your left input expression is a temperature, and suppose max() were able to handle units properly. But you do not attach a unit to your second parameter, 0, so the output would depend upon what the run-time temperature unit happened to be. max(a_temperature, 0 Celsius) might be a very reasonable operation, but if you do max(a_temperature, 0 with no unit) then the output would be very different if the run time temperature units happened to be Fahrenheit than if they happened to be Kelvin.
If you happened to be working with dimensionless quantities then the units configured at run-time could not affect the outcome of the expression, but since you are not working with dimensionless quantities, SimBiology worries that the MATLAB function you call is not correct to get all the units right.
If you are working with units that happen to be such that changing unit system could not affect sign() of the expression, then you could just ignore the warning. And it is just a warning. And everything might be fine. (Until, that is, the day that Some Idiot comes along and decides to run the model substituting pounds-force for kilograms and then complaining that your model doesn't work in orbit...)
2 Comments
Walter Roberson
on 8 Aug 2016
Right, just double-check your units, asking yourself "If the user changed the units to a different equivalent unit, when would this expression still work?"
More Answers (0)
Communities
More Answers in the SimBiology Community
See Also
Categories
Find more on Extend Modeling Environment in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!