Skip to main content
1-Visitor
December 3, 2015
Solved

Question of setup a condition for IF ELSE calculation

  • December 3, 2015
  • 5 replies
  • 4117 views

Hi all, I have a question of properly setup the if condition in Mathcad, would someone help me with the attachment? Thank you!

Best answer by MJG

How about this?  others may have a better way to handle condition1.

5 replies

MJG1-VisitorAnswer
1-Visitor
December 3, 2015

How about this?  others may have a better way to handle condition1.

23-Emerald IV
December 3, 2015
1-Visitor
December 3, 2015

After further consideration, I like this solution better.  It allows you to have better descriptive error text.

25-Diamond I
December 3, 2015
23-Emerald V
December 3, 2015

Just a general observation, it's often better to use the forms

rather than

as there can be a danger that both conditions a and b could be true, which means you end up getting result y even though you really wanted x.

There's no need for the return statement in the "return z" line above;

I just find it more informative and consistent that way,

Stuart

19-Tanzanite
December 3, 2015

as there can be a danger that both conditions a and b could be true, which means you end up getting result y even though you really wanted x.

IMO, this is another example where Prime is better than MC15. In MC15 the "otherwise" is attached to the preceding "if". The first "if" is completely independent. Prime changes "otherwise" to "else" (a change not liked by some because it's more like a programming language and less like math notation, but I can live with it), and adds "else if" and "also if", so we can have much more versatile, and better structured, conditional statements.

1-Visitor
December 4, 2015

Stuart, thanks for the suggestion.  I don't do a lot of programming in Mathcad.

Richard, I don't think this statement is accurate:

In MC15 the "otherwise" is attached to the preceding "if". The first "if" is completely independent.

From Mathcad Help:

"If you use more than one if statement before an otherwise statement, the otherwise statement is executed only when all previous conditions are false."