Page 1 of 1
Improving iterations!
Posted: Fri Aug 14, 2015 2:30 pm
by luisangelguzmang
Hi, can you help me to do this in a better, simple and/or elegante way?
I start whit the "matrix 0" and the vectors "generation" and attraction", these are constants and the result is the "matrox 6".
It is possible to do this in one step and do more iterations?
Thanks a lot!
Re: Improving iterations!
Posted: Sat Aug 15, 2015 7:23 pm
by Administrator
It's not clear to me what you are trying to do.
Does the FIND ZERO function help you at all? That can be used to iterate.
Re: Improving iterations!
Posted: Wed Aug 19, 2015 12:51 pm
by luisangelguzmang
I tried with FIND ZERO function,but I can't (I did not know) do anything, because I got 2 subindex. I apologize if i was not clear.
I need to estimate a future matrix (in this case "matrix 6") which is derived from base year matrix ("matrix 0") and the vectors "generation" and "attraction". There are four basic steps to the calculation:
1. The vector "generation" is divide by the sum the row data for each zone in "matrix 0" to obtain a growth factor by rows.
2. Multiply the lines in the "matrix 0" by the appropriate factor found in the previous step ("matrix 1").
3. Now, the vector "attraction" is divide by the sum the column data for each zone in "matrix 1" to obtain a growth factor by columns. The result is "matrix 2".
4. Repeat the iteration process until the row or column factor being calculated is sufficiently close to 1.
The equation is:

- eq
- img.jpg (9.72 KiB) Viewed 8972 times
where tij is the "maxtrix 0" data, t'ij is the result "matrix 6", Pi is the "generation" vector, Aj is the "attraction" vector, and pi and aj are the sum of rows and columns for each interation ("matrix k"), respectively. So, the iteration stops when Pi/pi and Aj/aj are equal to 1 (or very close).
In summary I will like to summarize all these loops (if is possible) in just one, doing several iterations, much more than 6...
Thks a lot!
Re: Improving iterations!
Posted: Mon Aug 24, 2015 1:57 pm
by luisangelguzmang
Hi, can you help me?? or is not possible?
Thks
Re: Improving iterations!
Posted: Mon Aug 24, 2015 2:05 pm
by Administrator
Can you upload the model you tried with FIND ZERO?
Re: Improving iterations!
Posted: Mon Aug 24, 2015 5:40 pm
by tomfid
To use find zero, you'd have to define a one-dimensional array i_j of size ELMCOUNT(i)*ELMCOUNT(j) and map t[i,j] to t2[i_j]. Then you could use the find zero functionality to iterate.
This would probably work better as an external function though.
Re: Improving iterations!
Posted: Mon Aug 24, 2015 5:42 pm
by tomfid
It would help to have a description of what you're trying to achieve with this calculation. There might be an easier way.
Re: Improving iterations!
Posted: Tue Sep 29, 2015 6:54 pm
by luisangelguzmang
Hi, this is my problem. I have tried to be as specific as possible.
I get an initial 4x4 (ij) matrix (M0) into the Vensim model. I get another two additional vectors where information is available on the expected growth in data cells originating (Oi) and terminating (Dj) in each zone. I need to obtain a new matrix (M6), in this case with 6 iteractions (see attached model). But, what if I need additional iterations?
Returning to the example, this implies different growth rates for data in cells ij in and out of each zone and consequently having two sets of growth factors for each zone, say ai and bj. I need an iterative method to obtain an estimated new matrix (M6, in this case) which satisfies both sets of data-end constraints (Oi and Dj). I tried with FIN ZERO function, but I could not do anything.
So, I made this model calculating a set of intermediate correction coefficients which are then applied to cell entries in each row or column as appropriate. After applying these corrections to say, each row, the totals for each column are calculated and compared with the target values (Oi and Dj). If the differences are significant, new correction coefficients are calculated and applied as necessary. So,incorporating the growth rates into new variables ai and bj:
M6 = M0 x ai x bj
Where the factors ai and bj must be calculated so that the constraints are satisfied (sum i and sum j must be equal or very close to 1). This is achieved in an iterative process which in outline is as follows:
1. set all bj=1 and solve for ai; in this context, ‘solve for ai’ means find the correction factors ai that satisfy the Oi constraints;
2. with the latest ai solve for bj, e.g. satisfy the Dj constraints;
3. keeping the bj’s fixed, solve for ai and repeat steps (2) and (3) until the changes are sufficiently small (sum i and sum j equal or very close to 1).
In sum, I really want to know if there is any better (and elegant) way to solve this problem, or definitely the better way is doing as the attached model as many times as I needed.
Thanks a lot!
Re: Improving iterations!
Posted: Wed Sep 30, 2015 1:28 pm
by LAUJJL
Hi
you may find some information about using arrays for looping in the following thread
http://ventanasystems.co.uk/forum/viewt ... ilit=+loop
There are some references to some other threads interesting too.
Regards.
JJ
Re: Improving iterations!
Posted: Wed Sep 30, 2015 4:38 pm
by Administrator
I think you probably need to go to an external function with this.