Skip to main content
1-Visitor
September 7, 2022
Solved

Boolean operator not working as expected

  • September 7, 2022
  • 1 reply
  • 981 views

Hello,

 

I am using a for loop to combine two small matrices. The intent is that if both values exceed 0.2, then the values at an index are to be added together. If either or both of the two values is less than or equal to 0.2, then only the greater of the two values is kept. For some reason, no matter what the index values are the condition where it takes the maximum always triggers.

BJ_10306618_0-1662561492857.png

However, when I tried putting parentheses around the boolean statement (just throwing stuff at the wall), the second operation would always trigger.

BJ_10306618_1-1662561557419.png

I don't understand where I'm going wrong here, I am not proficient with programming in Mathcad.

Best answer by Werner_E

You have to write     if (DC.V[i <=0.2) v (DC.T[i <=0.2) 

The parenthesizes are optional, "<=" has priority over "v". This is also the reason why your condition always triggers.

What you wrote is interpreted as    if (DC.V]i) v (DC.t]i <= 0.2)    and because any non-zero value is interpreted as TRUE and in your case all DC.V.i are non.-zero, the combined condition is always true.

 

EDIT: You may replace your OR condition by   if  min (DC.V[i, DC.T[i) >= 0.2 and exchange the if- and else branch if you like.

1 reply

Werner_E25-Diamond IAnswer
25-Diamond I
September 7, 2022

You have to write     if (DC.V[i <=0.2) v (DC.T[i <=0.2) 

The parenthesizes are optional, "<=" has priority over "v". This is also the reason why your condition always triggers.

What you wrote is interpreted as    if (DC.V]i) v (DC.t]i <= 0.2)    and because any non-zero value is interpreted as TRUE and in your case all DC.V.i are non.-zero, the combined condition is always true.

 

EDIT: You may replace your OR condition by   if  min (DC.V[i, DC.T[i) >= 0.2 and exchange the if- and else branch if you like.