cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

Boolean operator not working as expected

BJ_10306618
1-Newbie

Boolean operator not working as expected

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.

1 ACCEPTED SOLUTION

Accepted Solutions

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.

View solution in original post

1 REPLY 1

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.

Top Tags