Skip to main content
1-Visitor
October 3, 2014
Question

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

  • October 3, 2014
  • 2 replies
  • 2332 views

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?

2 replies

1-Visitor
October 3, 2014

Please upload your worksheet.

25-Diamond I
October 3, 2014

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

23-Emerald V
October 3, 2014

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

25-Diamond I
October 3, 2014

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