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

Self-Rererential Programs

IanB
2-Explorer

Self-Rererential Programs

Hello,

 

I recently updated from Mathcad 15 to Mathcad Prime (8.0) and am having a problem with certain worksheets that contain a specific type of program. Specifically, programs where the calculation is dependent upon elements from the output vector that should already have been calculated. ie 

 

x[i = x[(i-1) + y[i

 

(sorry for the notation - can't work out how to get subscripts on this forum).

 

I have attached a simple example worksheet of the problem. Is this type of self-referential programming no longer possible. If so can anyone suggest a work-around?

 

IanB_0-1696863298122.png

 

 

Apologies if this question has been asked and answered already. I had a look using the search function but was not able to find anything obvious. Many thanks for any assistance.

 

Ian

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:IanB)

I can confirm that the behaviour is different from the one in real Mathcad 15. You may consider reporting it to PTC as being a bug.

 

As a workaround you could do without the range i using a for-loop. So you could just copy the old program in place:

Werner_E_0-1696869387809.png

The initialization could also be done directly without the if-statement and in your case there is no need to distinguish between i=1 and i>1

Werner_E_3-1696869750004.png

In case you have an example where the second value (i=1) also differs from the rest. you initialize with the appropriate vector and start the loop with 2

Werner_E_4-1696869846184.png

 

If you really want to use a worksheet range, you would have to do the initialization explicitly first and use a range starting just from 1.

Werner_E_2-1696869571065.png

 

EDIT: Another option, which I won't recommend, could be to turn the existing program into a recursive function and call it using the range i

Werner_E_5-1696870483992.png

 

I don't have P8 installed so the attached sheet is in P9 format. But you should see all thats needed in the pics anyway.

 

 

 

View solution in original post

2 REPLIES 2
Werner_E
25-Diamond I
(To:IanB)

I can confirm that the behaviour is different from the one in real Mathcad 15. You may consider reporting it to PTC as being a bug.

 

As a workaround you could do without the range i using a for-loop. So you could just copy the old program in place:

Werner_E_0-1696869387809.png

The initialization could also be done directly without the if-statement and in your case there is no need to distinguish between i=1 and i>1

Werner_E_3-1696869750004.png

In case you have an example where the second value (i=1) also differs from the rest. you initialize with the appropriate vector and start the loop with 2

Werner_E_4-1696869846184.png

 

If you really want to use a worksheet range, you would have to do the initialization explicitly first and use a range starting just from 1.

Werner_E_2-1696869571065.png

 

EDIT: Another option, which I won't recommend, could be to turn the existing program into a recursive function and call it using the range i

Werner_E_5-1696870483992.png

 

I don't have P8 installed so the attached sheet is in P9 format. But you should see all thats needed in the pics anyway.

 

 

 

IanB
2-Explorer
(To:Werner_E)

Hi Werner,

 

Thanks so much for your extensive reply. I'm sure there is one of the options that you have presented that will work for our purposes. I'll report the issue as a bug to PTC.

 

Ian

Announcements

Top Tags