Expressions


Examples

The following are some sample expressions and how they are evaluated in Simulation Studio.

  1. The expression (AttributeA || AttributeB) && (! AttributeC) evaluates to true if the following two conditions are both satisfied: either AttributeA or AttributeB is true, and AttributeC is false.

  2. Assume the following values:

    Attribute = 1, Attribute2 = 2, Attribute3 = 1, Attribute4 = 5, Attribute5 = 2, and Attribute6 = 4.

    ((Attribute + Attribute2 – Attribute3) * Attribute4 / Attribute5) % Attribute 6

    evaluates to 1 because 1 + 2 – 1 is 2, the result 2 multiplied by 5 is 10, the result 10 divided by 2 is 5, and the remainder of 5 divided by 4 is 1.

    Attribute2 == Attribute5

    evaluates to true because both Attribute2 and Attribute 5 have the same value.

    max(Attribute6,Attribute5,Attribute4)

    evaluates to 5 because Attribute4 has a value of 5, which is larger than the values of the other two attributes.

    maxindex(Attribute6,Attribute5,Attribute4)

    evaluates to 2 because Attribute4 has a value that is larger than the values of the other two attributes. Furthermore, the zero-based index of Attribute4 in the list of arguments is 2 (Attribute6 has index 0 and Attribute5 has index 1).

  3. Assuming MyNum is –13.5, the expression abs(floor(MyNum)) evaluates to 14 because the floor of –13.5 is –14 and the absolute value of –14 is 14.

  4. If MyNum=2000/3=666.666666, then

    \begin{eqnarray} \Strong{round(MyNum)} & =& 667.0 \nonumber \\ \Strong{round(MyNum,0)} & =& 667.0 \nonumber \\ \Strong{round(MyNum,1)} & =& 670.0 \nonumber \\ \Strong{round(MyNum,2)} & =& 700.0 \nonumber \\ \Strong{round(MyNum,3)} & =& 1000.0 \nonumber \\ \Strong{round(MyNum,--3)} & =& 666.667 \nonumber \end{eqnarray}
  5. Assume the following values: A="One", B="Two", and C="Three". Then the expression
    concat(A,B,C) evaluates to "OneTwoThree".

  6. The expression substring("Attribute1",2,4) evaluates to "trib".

  7. The expression substring("Attribute1",2,-3) evaluates to "Att".

  8. Assume Input=3. Then the expression cond(Input%2==0,1,2) evaluates to a value of 2 because the Boolean expression in the first argument is false. Therefore, the third argument is returned.

  9. Assume the following values: X=3, Y=2, and Z=4. Then the expression
    cond(X < Y,0, cond(X < Z, 1, 2)) evaluates to 1 because X < Y is false and X < Z is true.

  10. Assume Input=45. Then the expression
    switch(Input <= 10, 1, Input > 10 && Input <= 20, 2, Input > 20 && Input <= 30 ,3, 0) evaluates to 0 because the three Boolean expressions all evaluate to false. If Input=25, then the same expression evaluates to 3.