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

SOLVED
Moonstone

## 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.

4.0 attached.

1 ACCEPTED SOLUTION

Accepted Solutions
Sapphire III
(in response to DJF)

## Re: Switch between input types

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

6 REPLIES 6

## Re: Switch between input types

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.

Alexandrite
(in response to DJF)

## Re: Switch between input types

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

Sapphire III
(in response to DJF)

## Re: Switch between input types

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

## Re: Switch between input types

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.

## Re: Switch between input types

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.

## Re: Switch between input types

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
Announcements
Check out the latest