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

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

Mathcad Prime: Ignore Units in Text Statement

seandonahue
4-Participant

Mathcad Prime: Ignore Units in Text Statement

I am trying to create a conditional program, that returns a value if the input is within a data set, but an error if the input value is outside the bounds of the data set. Unfortunately, the return value is in a non-default unit (psi*ms). Thus, if I just set the formula to show the default result, the displayed units are not what I want. However, if I go in and set the units to my desire value in the result, the display will then "crash" if it tries to return the error message.

Is there a way to get mathcad to "ignore" the units if it is returning text?

The worksheet in question is very busy, so I have isolated an example of the idea in the attached sheet.

Basically, I want Impulse(6) to return a value in psi-ms, but Impulse(2) to return the error message.

Is there any way to get Mathcad Prime to do this?

Thanks in advance,

1 ACCEPTED SOLUTION

Accepted Solutions

You may consider replacing the text by NaN (still not looking like what you want to see, I know).

The problem is that Prime won't let you multiply a text by a unit.

Here is an approach which separates the message text from the resulting value:

Werner_E_0-1578084954780.png

 

View solution in original post

8 REPLIES 8

You may consider replacing the text by NaN (still not looking like what you want to see, I know).

The problem is that Prime won't let you multiply a text by a unit.

Here is an approach which separates the message text from the resulting value:

Werner_E_0-1578084954780.png

 

seandonahue
4-Participant
(To:Werner_E)

That does address the issue of the formula not running, but my bigger desire is to make it convey the desired information. I'd prefer the formula to actually display the specific error message so someone reading the worksheet can easily interpret what's happening. I don't feel like the "not a number" solution really conveys anything that the current "?" result doesn't already convey.

So separating the message from the numeric as added to my above result may be an option. The NaN "value" assures that calculations done with that value will fail (in the sense that the result is again a NaN and so can easily be spotted. The message text part can explain in detail why.

BTW, your routine does not cover the case x=5 .

I can't program it (Express can't program) but try this:

FredKohlhepp_0-1578143436045.png

 

Yes, thats basically the same as  seandonahue  did, using programmed if command instead of the if function.

Unfortunately the problem is the same, too:  The region, where the result is shown in psi*ms, fails, if the value of x is out of bounds.

What's not clear is what value should be returned if the input is "out of bounds".  Returning NAN is one option, that would let the operation proceed:

 
 

 

 


@Fred_Kohlhepp wrote:

What's not clear is what value should be returned if the input is "out of bounds".  Returning NAN is one option, that would let the operation proceed:

As I understood @seandonahue  wanted the result either to be a valid value (with units) OR that error string. In case of x not within the valid range, the variable holds that string as value and all subsequent calculations using this value will fail and throw an error. As I understood this is OK as long as the message "Out of Bounds" is displayed in front. This works in your and his approach pretty OK until you decide to display the result in different units. When you add the unit you'd like to see, the region fails if the value of x is out of bounds and does not display the appropriate value. The reason for this is that Prime does not allow a string to be multiplicated by a unit.

Thats the reason I suggested to split variable holding the value and the message string. It also looks cleaner to me not to assign a string to a variable which normally is supposed to hold a numeric result.

seandonahue
4-Participant
(To:Werner_E)

Okay. It's marginally less concise than what I was hoping for, but splitting the error message and actual result calculation up should enable me to convey what I was hoping for, just needs a few more steps. 

Thanks for the advice.

Top Tags