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

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

Switch between input types

DJF
16-Pearl
16-Pearl

Switch between input types

I'm often provided with a flow rate, but it can be specified in either volume flow or mass flow.  I want a simple way for my sheets to work regardless of what is specified (i.e. calculate the one that isn't defined from the other).  My goal is to have the two inputs, but the one I don't need is disabled.  I thought this would be easy, but I'm not finding a solution other than to enable/disable equations (which could get messy and dangerous) or assign flags telling mathcad what to do (also dangerous).  In excel I could use ISNUMBER or similar, but I don't seem to find that in Mathcad.  I thought TRY would work, but even that quits when it reaches an undefined variable.  I tried a few things with NaN but still no luck.  Any suggestions?  Thanks.

2019-12-17_8-24-01.jpg

 

4.0 attached.

1 ACCEPTED SOLUTION

Accepted Solutions
Fred_Kohlhepp
23-Emerald I
(To:DJF)

What might work would be to predefine both flow rates negative.  (You could put this at the top in a closed area so it doesn't show.)  Down where it matters you define the one you have, then a simple if statement will do what you want.

 

Prime 4.0 attached

View solution in original post

6 REPLIES 6
Werner_E
24-Ruby V
(To:DJF)

AFAIK there is no way to check if a variable already has been assigned a value.

You may set a variable to NaN and check using IsNaN(variablename).

Or you may set the variable to Zero or to string saying "not assigned" and check for that.

The point is, that the variable must have been assigned any value if you intend to use it in your routine.

 

tietjee
14-Alexandrite
(To:DJF)

Prime does not a function to determine is a variable is defined.  Attached is snippet that is a work around, but not a complete solution.

 

Cheers 

Fred_Kohlhepp
23-Emerald I
(To:DJF)

What might work would be to predefine both flow rates negative.  (You could put this at the top in a closed area so it doesn't show.)  Down where it matters you define the one you have, then a simple if statement will do what you want.

 

Prime 4.0 attached

Thanks Fred.  A bit unusual but that should work.  A slight improvement would be to define them as imaginary numbers instead of negatives.  Either way works but if you started with multiple streams and adding flows, a negative could get lost.  However I'm unlikely to have a imaginary flow rate.

Werner_E
24-Ruby V
(To:DJF)

In my opinion NaN would be a more "natural" initial assignment compared to negative or non-real numbers (with units!?), because NaN tells the whole story - its "not a number". Using that variables in calculations with units should not throw any error and any calculation done with them should result in NaN, too, so its easy to spot.

 

Agree I use NaN a lot for non used value say in optimal arguments. In my opinion this is ex at a situation made for NaN
Top Tags