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

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

If statement not working after Mathcad 15 to Mathcad Prime 3 conversion.

ptc-1020524
1-Newbie

If statement not working after Mathcad 15 to Mathcad Prime 3 conversion.

If statement not working after Mathcad 15 to Mathcad Prime 3 conversion.

nn = 0, 1, .. 499

P[nn := if(nn = 0, S[0, P[(nn-1) - S[n)

Mathcad Prime complains that P[(nn-1) is not defined, but works in Mathcad 15.

Any suggestions on how to fix this?

7 REPLIES 7
MikeArmstrong
5-Regular Member
(To:ptc-1020524)

Please upload your worksheet.

Thats interesting. Obviously the behaviour of how expressions with range variables are evaluated and assigned has changed.Or is it the if-functions which acts differently now? Don't know, would have to further investigate.

But easy solutions are at hand quickly. Most obvious one is to define the first value in P in a separate expression.

It does not matter what value P[0 is assigned to - Prime just insists that P[0 to be defined. So I guess the problem has to do with the combination of shortcut evaluation of if and usage of ranges - not sure, though.

1.png

The if-function is obsolete now and you could also use

2.png

In your case you might also consider replacing the recursion by a more direct calculation

3.png

StuartBruff
23-Emerald II
(To:Werner_E)

It would be intersesting to look at the help for "if" in Prime (I don't have it and can't download to my work PC).

In M15, if(cond,x,y) only evaluates y if cond is false, hence for n=0, M15 doesn't evaluate Pnn-1 = P0-1 and therefore doesn't complain about the invalid index.

Stuart

You may not have access to Prime, but you can look at the help online here http://www.ptc.com/cs/help/mathcad_hc/prime3_hc/

I could not find a help page for the if function. It should be in "Piecewise Functions".

Neverthelesse, shortcut evaluation as you described seems still be implemented in if as the following shows.

5.png

So it could have something to do with evaluating expressions with ranges.

BTW, here is yet another appraoch using a recursive function

4.png

StuartBruff
23-Emerald II
(To:Werner_E)

Werner Exinger wrote:

You may not have access to Prime, but you can look at the help online here http://www.ptc.com/cs/help/mathcad_hc/prime3_hc/

I could not find a help page for the if function. It should be in "Piecewise Functions".

Unfortunately, I guess because I'm not on any kind of maintenance and wasn't involved in the last round of Prime testing, I don't have permission to view that page or any other product documentation.

Which is an interesting contrast to Matlab and Mathematica, where Mathworks and Wolfram will cheerfully let me have access to their complete documentation without an account.

Stuart

StuartBruff wrote:

Werner Exinger wrote:

You may not have access to Prime, but you can look at the help online here http://www.ptc.com/cs/help/mathcad_hc/prime3_hc/

I could not find a help page for the if function. It should be in "Piecewise Functions".

Unfortunately, I guess because I'm not on any kind of maintenance and wasn't involved in the last round of Prime testing, I don't have permission to view that page or any other product documentation.

I wasn't aware that those pages would require being under maintainance but it seems to be true, I just tried with a test account. Thats absurd and ridiculous indeed.

RichardJ
19-Tanzanite
(To:StuartBruff)

Unfortunately, I guess because I'm not on any kind of maintenance and wasn't involved in the last round of Prime testing, I don't have permission to view that page or any other product documentation.

The only thing that matters is maintenance. I don't have access either. It's understandable why PTC does not want to give active support to those that are not on maintenance, but not allowing all customers to read help and knowledge base files is ridiculous. It's like they want their non-maintenance paying customers to fail!

Top Tags