cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

Iterative calculation problem

ptc-947262
1-Newbie

Iterative calculation problem

Please open attached file. Equations shown are simplified to show the problem. Equation 1 as you can see works fine. I had to seed a0 and a1 to get the iteration started but it went on finding intermediate results and applying them to the next calculation just fine. Equation 2 adds an intermediate calculation but does the same thing as Eq 1. For the first iteration, it's good. Equation 3 shows the second iteration. It works because b2 was calculated in Eq 2 above. But in Eq 4 the solution fails because (I think) when calculating F4 it no longer "remembers" that calculated b4 during the i-3 loop. Any suggestions? Using an equation 1 format works with this simplified version but not so well in the real work.
3 REPLIES 3

For equations 2, 3, and 4 you have two separate equations, each of which iterates separately, independent of the other. If you have interdependent calculations, they must be part of a single calculation. I would recommend a program structure with an explicit for loop for the purpose. I think it's simpler and clearer. If, for some reason, you insist on the range variable iteration you need to have a vector of expressions assigned to a vector of values. That way you have a single region and it all iterates at once.

Thanks for the help Tom. Although I have used MathCAD forever, I don't commonly use the more advanced features. Range variable use is pretty hi-tech for me. Can you point me towards an example of the use of "vector of expressions assigned to a vector of values"? Bob

It should be in the documentation. It is a vital construct for doing significant iterations using just range variables. But I can't find it in the documentation and it may well no longer be there (the documentation of Mathcad is atrocious). I suggest posting the question in the collaboratory, where it is easier to upload files, and where such uploading does not run into quota issues. But the construct is just what I stated. You insert an array constructor (ctl-m) on the left of the :=, in there you put the names (possibly, and usually, subscripted) which you wish to define and on the right you put a matching array (usually also using an array constructor, but it could be built with a program structure) in which you put the values (generally as expressions to be evaluated) to be assigned. Where range variables are used on the left all assignments for one value for the ranger variables are done at a time, before moving on to the next range value. But still, I suggest using a for loop rather than range variables for anything beyond the trivial. You will have less problems and make less mistakes that way.
Top Tags