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

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

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?

1 ACCEPTED SOLUTION

Accepted Solutions
23-Emerald III
(To:Johnruehlz)

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

Success!
Luc

4 REPLIES 4
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

7-Bedrock
(To:LucMeekes)

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.

7-Bedrock
(To:LucMeekes)

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

23-Emerald III
(To:Johnruehlz)

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

Success!
Luc

Announcements
Top Tags