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?
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.
The if-function is obsolete now and you could also use
In your case you might also consider replacing the recursion by a more direct calculation
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.
So it could have something to do with evaluating expressions with ranges.
BTW, here is yet another appraoch using a recursive function
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.
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!