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

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

Using = in if statement

Johnruehlz
7-Bedrock

Using = in if statement

First of all thank you for helping me. I am trying to figure out a way to use a if statement to compare to see if two variables are equal to each other?

ACCEPTED SOLUTION

Accepted Solutions
LucMeekes
23-Emerald III
(To:Johnruehlz)

Yes, it works for Mathcad 15, 14, 13, 12, 11 and below.

 

LM_20171009_Compare.png

 

Success!
Luc

View solution in original post

4 REPLIES 4
LucMeekes
23-Emerald III
(To:Johnruehlz)

You should first know that comparing for equality is to be used with caution.

Note that Mathcad is software that uses approximations for numerical values only. You should not be surprised if, when a is assigned the value 1/9 and b is assigned the value 1, then the comparison 9*a = b would render False { that is: 0, instead of 1 for True}.

 

Having said that, you can use an equals statement in an if statement:

if(a=b,3,4)

results in 3 if a=b, and 4 if a is unequal to b.

Taking account of numerical approximations, it is generally better to compare a to b with:

if(|a-b|<delta,3,4). And be sure to assign an appropriate positive value to delta beforehand.

 

Success!
Luc

 

Thank you these values are all input variables coming for an excel spreadsheet I just to trying to write a function I can call to determine which input variables are the same.

Does this work for MathCad 15 sorry forgot to mention that...

LucMeekes
23-Emerald III
(To:Johnruehlz)

Yes, it works for Mathcad 15, 14, 13, 12, 11 and below.

 

LM_20171009_Compare.png

 

Success!
Luc

Announcements

Top Tags