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

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

if function

wkhalid
1-Visitor

if function

Hi

How can I use if function when I have two statement shall be valid at the same time:

For example:

y=0 if x=5 and z=10

y=1 otherwise

How can I replace "and"?

Thanks

ACCEPTED SOLUTION

Accepted Solutions

10 REPLIES 10

Like so.

Clipboard01.jpg

Sorry, the and function can be found on the Boolean toolbar or by Ctrl+&.

if function not operator:

y:=if(x=5 ^ z=10, 0, 1)

or

y:=if(x=5, if((z=10, 0,), 1)

Of course Valery. There is more thanone way to skin a cat

Mike Armstrong wrote:

Of course Valery. There is more thanone way to skin a cat

But only one is correct

Do you know differents:

y:=if(x=5 ^ z=10, 0, 1)

y:=if(x=5, if((z=10, 0, 1), 1)

y:=if(z=10 ^ x=5, 0, 1)

y:=if(z=10, if((x=5, 0, 1), 1)

You sure!!!!

Clipboard01.jpg

If x not equal 5 we do not need to check z=10: if..(if.. is more correct than ... and ...

Valery Ochkov wrote:

If x not equal 5 we do not need to check z=10: if..(if.. is more correct than ... and ...

Its sure equally correct but it may be a bit more efficient.

Werner Exinger wrote:

Valery Ochkov wrote:

If x not equal 5 we do not need to check z=10: if..(if.. is more correct than ... and ...

Its sure equally correct but it may be a bit more efficient.

Why I point it!?

Two days ego I have corrected one function in WaterSteamPro set - I have replaced the end operator on two if/ Now we have no error in it!

Why I point it!?

Two days ego I have corrected one function in WaterSteamPro set - I have replaced the end operator on two if/ Now we have no error in it!

Not sure what you mean by "replace end operator".

When evaluating a combined boolean expression, Mathcad uses shortcut evaluation - sometimes also calles short-circuit evaluation. That means if we have ... A AND B .... and A is already false, B is not evaluated at all. This is very often convenient but its dangerous because as far as I know its not documented so PTC may change that behaviour without notice. So the order of the operands in a logical combined expression matters and you are on the safe side, if you use nested if's. Not considering this may have been the casuse for the error in your sheet.

1.png

Announcements

Top Tags