Skip to main content
1-Visitor
August 30, 2016
Solved

Need some help with IF statement

  • August 30, 2016
  • 6 replies
  • 13282 views

Hello,

For a Mathcad calculation I am trying to make use of an IF statement in Mathcad 15. At the top of the sheet I ask the user of the sheet whether they want calculation "A" or "B" through a List Box Control. I have set name "A" to correspond with value "0", and name "B" to correspond with value "1". This value is then stored as follows:

Snip1.png

Then further down in the Mathcad sheet, I want to make an IF program that calculates a function in one of two ways, depending on the value of Storage. I tried to make it like this, but that did not work:

Snip2.png

Does any of you have tips for me on how to do this? I know that what I am currently doing makes no sense in Mathcad language, but I think it best illustrates my problem.

Thanks in advance!

Tim

Best answer by MJG

6 replies

23-Emerald I
August 30, 2016

You're actual not far off. 

24-Ruby IV
August 30, 2016

See please pictures and attach

1-Visitor
August 30, 2016

I tried to make it like this, but that did not work:

Snip2.png

Can you clarify what "did not work" about this equation?

As Fred shows in his example, it can be good to include an "Otherwise" statement.  However, as long as "Storage" is either equal to 1 or 0 (which your input control forces), the "Otherwise" is not strictly necessary.

Based on appearance, your equation should work.  Can you either post your file or better explain why you say it doesn't?

MJG1-VisitorAnswer
1-Visitor
August 30, 2016
tvk1-VisitorAuthor
1-Visitor
August 30, 2016

Apologies that it now has other variables, but I did not feel like changing them to something more anonymous again..

Here the Storage value is 0 (now called Soiltype)

Snip1.png

Here the Storage value is 1 (now called Soiltype)

Snip2.png

And these are the values of the individual functions, just to prove that they are indeed different values

Snip3.png

1-Visitor
August 30, 2016

Also, FYI, I disagree with you:

I know that what I am currently doing makes no sense in Mathcad language

I think what you're doing makes perfect sense.  I'm sure some may prefer a different format, but the concept of what you're doing is exactly what Mathcad was designed to do.

23-Emerald V
August 30, 2016

Just an addendum to Fred's original answer ...

It's often "cleaner" (for values of clean) to make functions self-contained rather than dependent upon some previously defined variable.  For example, you might want to use the same formula later in a worksheet but with a different value of Storage.

In addition, Mathcad 15's if statement's sometimes need a bit of care to avoid errors that may arise from successive if statement conditions being true.

Stuart

24-Ruby IV
August 30, 2016

We can show not all formulas but the formula in this calculating case:

Try please this Mathcad web-sheet:

http://twt.mpei.ac.ru/MCS/Worksheets/Hydro/GDF.xmcd