Get Help

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Community
- :
- PTC Mathcad
- :
- PTC Mathcad
- :
- Mathcad ignore evaluation in false if statements

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

06-07-2019
04:53 PM

06-07-2019
04:53 PM

I am trying to define a piecewise function in Mathcad to move around singularities, but the program breaks down at the singularities even when they are not called.

I created a program that evaluates one function if "w" is greater than or equal to "r", and another function if "w" is less than "r". The second function has a singularity if "w" is equal to "r" but theoretically it shouldn't need to evaluate that function in that case, as "w" isn't less than "r". The program still returns an error in that case though.

Is there a way to set up the program such that MathCad will not try to evaluate the term in the false if statement

Example:

function = if w >= r

pi/2

if w < r

atan(1/(w-r))

Solved! Go to Solution.

Labels:

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

06-08-2019
08:35 AM

06-08-2019
08:35 AM

I second what Luc wrote about the worksheet. It should be possible in most cases to narrow down the problem and create and post a worksheet which shows what you are looking after and what fails.

In case of your problem this should be fairly simple! Its still unclear for example if w and r are defined on top of your sheet or if they are provided as function arguments. And you always talk about functions but you don't show any function. So its unclear if you are just sloppy when typing in here the part of the expression or if you misunderstood the meaning of a function in math and confuse it with "term" or "expression". When you write

F2=atan(1/(w-r))

thats not a function but rather the definition of a new variable F2 which Prime tries to evaluate no matter what the values of w an r are. Of course, when the variables w and r are defined above with the same value, this calculation obviously must fail.

If you really insist in splitting this simple and straightforward calculation into a series of single calculations, you may do it with functions like this:

Note that if w and r are defined above, fun must not necessarily be a function but may be a simple variable. F2 has to be a function which is only called when w and r are different.

And here are different approaches without any functions:

6 REPLIES 6

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

06-07-2019
05:09 PM

06-07-2019
05:09 PM

Re: Mathcad ignore evaluation in false if statements

You should attach your worksheet, not just a description what you had done. Its hard to determine what you may have done wrong just from the description. Furthermore you should state which version and which flavor of Mathcad (Prime or real Mathcad) you are using.

You may consider using the "otherwise" (= "else") statement instead of a second "if".

You may also use the if-function (similar syntax as in Excel) instead of the if-programming-statement.

BTW, while I would not suggest doing so, but it works OK even the way you describes it:

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

06-07-2019
05:29 PM

06-07-2019
05:29 PM

Re: Mathcad ignore evaluation in false if statements

Unfortunately, I cannot post the worksheet due to security restrictions on the project. However, based on your feedback, I have narrowed the problem down further.

The program does execute if I type the entire formula into the program if statement. However, the worksheet is set up where I define a bunch of separate functions that the program selects from. In that case, the fact that the earlier function is undefined causes the program to crash.

Further clarification

F1 = pi/2

F2 = atan(1/w-r)

Function = if w>=r

F1

if w<r

F2

Program crashes at w=r in that case ( it also crashes if I set it up with an if-function or an else statement). This does give me a workaround if I directly type the function into the program, but the presentation is better if I can nest the functions, so I would like to still do that if possible.

Sadly, I no longer have access to real mathcad and am using Mathcad Prime 4.0

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

06-07-2019
06:10 PM

06-07-2019
06:10 PM

Re: Mathcad ignore evaluation in false if statements

1. You don't need to submit your entire sheet. If you are allowed to publicise your construct in a clumsy textual way, you could also put that part in a (separate) worksheet and attach that, so: you should attach a (just a) sheet that describes your problem as concise as possible. (Yes, a picture may paint a thousand words, but a worksheet is superior to a picture!)

2. If properly formulated, the if statement WILL do the trick, as shown here

with w below, equal to and above r. No crash.

Success!

Luc

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

06-08-2019
08:35 AM

06-08-2019
08:35 AM

I second what Luc wrote about the worksheet. It should be possible in most cases to narrow down the problem and create and post a worksheet which shows what you are looking after and what fails.

In case of your problem this should be fairly simple! Its still unclear for example if w and r are defined on top of your sheet or if they are provided as function arguments. And you always talk about functions but you don't show any function. So its unclear if you are just sloppy when typing in here the part of the expression or if you misunderstood the meaning of a function in math and confuse it with "term" or "expression". When you write

F2=atan(1/(w-r))

thats not a function but rather the definition of a new variable F2 which Prime tries to evaluate no matter what the values of w an r are. Of course, when the variables w and r are defined above with the same value, this calculation obviously must fail.

If you really insist in splitting this simple and straightforward calculation into a series of single calculations, you may do it with functions like this:

Note that if w and r are defined above, fun must not necessarily be a function but may be a simple variable. F2 has to be a function which is only called when w and r are different.

And here are different approaches without any functions:

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

06-08-2019
08:59 AM

06-08-2019
08:59 AM

Re: Mathcad ignore evaluation in false if statements

@seandonahue wrote:

Sadly, I no longer have access to real mathcad and am using Mathcad Prime 4.0

If you have Prime 4.0, the full version that will allow programming, then you have a license. That license entitles you to a functioning copy of Mathcad 15.

Without a license you have Prime 4.0 Express, and much of what's been shown here you cannot use. The only if statement available to you is the "EXCEL" if statement.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

06-10-2019
11:10 AM

06-10-2019
11:10 AM

Re: Mathcad ignore evaluation in false if statements

Apologies. I am new to asking for support, and forogt the importance of being extremely explicit with my terminology. I was using "function" in the general sense, and not the MathCad one. Keeping the "functions" as actually functions (dependent on the input variables) in the prgram has eliminated the crashing problem. I had to move a few lines around so the worksheet still flows logically, but it's producing the needed results now. Thank you very much for your assistance

Top Tags