Skip to main content
1-Visitor
October 6, 2021
Solved

Formula that uses previous result

  • October 6, 2021
  • 1 reply
  • 1914 views

Hello!

I am trying to write this formula:

MR_10045948_0-1633514673630.png

It uses the previous result (i-1) to calculate the next result (i). 

How should it be written in mathcad? Right now I get an overflow or infinite recursion error.

 

Best answer by LucMeekes

It's no problem to define a recursive function in Mathcad, but you have to provide a starting value.

LucMeekes_0-1633516502248.png

 

In your case: Where does i start, and what is the corresponding Ts,i value ?

 

Be sure to attach your worksheet, that'll help us better to help you.

 

Success!

Luc

1 reply

LucMeekes23-Emerald IVAnswer
23-Emerald IV
October 6, 2021

It's no problem to define a recursive function in Mathcad, but you have to provide a starting value.

LucMeekes_0-1633516502248.png

 

In your case: Where does i start, and what is the corresponding Ts,i value ?

 

Be sure to attach your worksheet, that'll help us better to help you.

 

Success!

Luc

1-Visitor
October 6, 2021

Thank you, I got it working! Recursive functions was what I was looking for. Although mathcad seems to get very slow when calculating recursive functions. For i=20, it takes around 10 seconds to calculate it, but at i=25 it already takes over a minute.

25-Diamond I
October 6, 2021

I suspect that this sure could be speeded up significantly.

Ts.,i-1 occurs twice in your formula and I guess you are calling the recursive function twice, which could be avoided by either rearranging the formula so T.s,i-1 occurs just once or by calculating it once in the function and store it in a variable.

Furthermore I suspect that T.g is provided as a vector of values and you are looking for the vector T.s and not for a generic function to calculate arbitrary T.s values. If thats true, the calculation should/could be done significantly faster as no recursion down to the first value is necessary.

But without seeing a´what exactly you do and need its hard to say more.