Skip to main content
1-Visitor
October 9, 2017
Solved

Using = in if statement

  • October 9, 2017
  • 1 reply
  • 9140 views

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?

Best answer by LucMeekes

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

 

LM_20171009_Compare.png

 

Success!
Luc

1 reply

23-Emerald IV
October 9, 2017

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

 

1-Visitor
October 9, 2017

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.