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

Need some help with IF statement

tvk
1-Newbie
1-Newbie

Need some help with IF statement

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

1 ACCEPTED SOLUTION

Accepted Solutions
MJG
18-Opal
18-Opal
(To:MJG)

15 REPLIES 15
Fred_Kohlhepp
23-Emerald I
(To:tvk)

You're actual not far off. 

ValeryOchkov
24-Ruby IV
(To:tvk)

See please pictures and attach

MJG
18-Opal
18-Opal
(To:tvk)

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?

MJG
18-Opal
18-Opal
(To:MJG)

tvk
1-Newbie
1-Newbie
(To:MJG)

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

StuartBruff
23-Emerald II
(To:tvk)

Tim vK wrote:

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

See my follow up to Fred's response.  You would probably benefit from making Soiltype an argument to the function su.AV.

Stuart

Stuart,

Are you suggesting that you think Tim's equation is wrong?  It seems to me that your suggestion is just an option that you perceive to be "cleaner."

Do you agree with me that Tim's equation should work as-is?

StuartBruff
23-Emerald II
(To:MJG)

Mark Gase wrote:

Stuart,

Are you suggesting that you think Tim's equation is wrong?  It seems to me that your suggestion is just an option that you perceive to be "cleaner."

Do you agree with me that Tim's equation should work as-is?

Hi Mark,

I agree that the *form* of Tim's equation *looks* correct, but without actually seeing a worksheet and looking at the detail, looks can be very deceptive.   I generally prefer to keep functions as stand-alone as I can because that tends to make them easier to test and less likely to be affected by unintended side-effects elsewhere in the worksheet.  

I'm glad to see that it works now he has invested it with Genuine People Personality.

Stuart

MJG
18-Opal
18-Opal
(To:tvk)

Tim, I'm sorry, but I still don't see what's causing the problem.  Did the worksheets posted by Fred and me work for you?  Can you post a stripped-down worksheet that we can open to see if we have the same results?

tvk
1-Newbie
1-Newbie
(To:MJG)

Mark, Stuart, thanks a lot for your help! I am currently writing what I want the sheet to do in a new sheet to see if this still produces the same errors, while using both your examples. I'll return later today (or tomorrow) with the results!

Edit:

I got it working, with exactly the same method that I used in my first upload. Just by re-typing it all in a new sheet.... I guess the problem is somewhere else in the sheet. Thank you both so much for the help! I did not think I had this in me already on the second day Mathcad

I have included my stripped down file, but you need the excel file to run it. Just in case you were wondering what the final result is.

StuartBruff
23-Emerald II
(To:tvk)

Random Data File attached ... just to check the mechanics.

tvk
1-Newbie
1-Newbie
(To:MJG)

What seems to happen in my sheet is that the answer to Fu(z) is always equal to the first function. It does not matter whether I change storage from A to B..

Unfortunately, I am not allowed to add my full sheet as an attachment.. But I'll make one that I can add in a few minutes.

MJG
18-Opal
18-Opal
(To:tvk)

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.

StuartBruff
23-Emerald II
(To:tvk)

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

ValeryOchkov
24-Ruby IV
(To:tvk)

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

Top Tags