Group Abstract Group Abstract

Message Boards Message Boards

0
|
6.7K Views
|
3 Replies
|
3 Total Likes
View groups...
Share
Share this post:
GROUPS:

minimum attribute versus assert function

Posted 12 years ago
POSTED BY: Mohamed Mahmoud
3 Replies
Posted 12 years ago

You can use the min and max attributes for parameters, like so:

parameter Modelica.SIunits.Length l1(min=0.4, max=1.5)=1 "A typical length";

If you try to enter a value for l1 that's outside of the range, a warning will appear in Model Center.

POSTED BY: Johan Rhodin
Posted 12 years ago

Thanks Sean for your reply. I am asking about the Modelica language. The code you are showing is Mathematica code, and I don't think it can be used inside SystemModeler.

POSTED BY: Mohamed Mahmoud

I'm not sure I understand what you mean by the "minimum attribute". Can you give an example of what you mean?

I normally do this by defining a pattern to be matched in the definition of the function

f[x_/;x>0] := x+1  (*Only runs if x>0*)
f[___] := Throw["Invalid input to f"]  (*Otherwise throw an error*)
POSTED BY: Sean Clarke
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard