Skip to main content
1-Visitor
July 7, 2011
Solved

Iterative / recursive program with multiple output ?

  • July 7, 2011
  • 3 replies
  • 5156 views

Hello,

I’m quite new to Mathcad and Mathcad Prime. I already looked for a solution in this forum and in the help files, but did not find anything suitable. Here’s my problem:

I defined a function f_next_s: Input s_n (current) -> Output s_n+1 (next).

function1.JPG

Now I want to repeat this procedure n times, starting with s_1(given):

Step INPUT (s_cur) OUTPUT (s_pre)

1 s_1 s_2

2 s_2 s_3

3 s_3 …

… … …

n s_n s_n+1

AND

I want to store the values of s_1, s_2, … s_n+1 so that I can go on calculating with them.

Here is what I tried, but it doesn't work (it only gives out the first result, which is s_2):

function2.JPG

Here ( http://communities.ptc.com/message/157701#157701 ) it says I should write the values in an array. But I can’t figure out how this works…

Can you please help me?

Best regards

Sebastian

Best answer by Fred_Kohlhepp

I don't have Prime in front of me right now, but I think the answer to your problem is that you're not making an array in your program. I've enclosed a short file in version 14 that illustrates.

I hope this helps.

3 replies

1-Visitor
July 7, 2011

Can you upload the worksheet?

Mike

1-Visitor
July 7, 2011

I thought it mitght be too confusing. But here it is.

There problem is situated at sheet 5 and 6.

Best regards

Sebastian

1-Visitor
July 7, 2011

I'm confused. The program you showed in your first post is not the same in your worksheet

Can you clearly indicate which function has the problem and list the expected results, sorry I am mad busy today and haven't got much spare time

Mike

23-Emerald I
July 7, 2011

I don't have Prime in front of me right now, but I think the answer to your problem is that you're not making an array in your program. I've enclosed a short file in version 14 that illustrates.

I hope this helps.

1-Visitor
July 8, 2011

Hello again.

Fred, thank you for your detailled explanation. I think this is exactly what I need!

But now there is another problem:

I can not create a subscripted "i-1" like this

example1.JPG

All I get in Mathcad Prime is a subscripted "i" minus the value 1

example2.JPG

How can I fix this?

-------------------- EDIT --------------

OK, I got it.

I can use the shortcut key "[" to define the matrix.

That's it!
Thank you all very much

Message was edited by: Sebastian Distler

19-Tanzanite
July 7, 2011

The last line should just be "s". If you return s[j then it will return only the element of s that corresponds to the current value of j (which is of course the last value).