MadonnaModel
Arial!D(.2>
B6:(,y
I{Model for figure 3b -- diffusion of information at rates inversely proportional to Euclidean distance}
METHOD RK4
STARTTIME = 0
STOPTIME=10
DT = 0.1
{the variables begin and end set up the range of the index that is used to define the dimensions of the grid, and the locations of squares on it. The variable begin should not be changed. The variable end defines the number of squares along both dimensions. For example, begin =1, end =5 would create a five by five spatial grid}
begin = 1
end = 3
{This is a reference table i found necesary to keep track of the informations when switching to a 2-dimensional array. the dimension are 'END X END' so this project it would be 3 X 3. Each element in the table is a diferent information going column by column. example:
1 4 7
2 5 8
3 6 9
this is the pattern it follows for any size table that is created. this makes it easy when looping to call a certain information.}
ref_table[begin..end,begin..end] = IF(i = 1) THEN j
else
ref_table[i -1, j] + end
{limit value of information quantities to positive}
limit inform >= 0
{initialize information quantities at each location}
init_inform[begin..end,begin..end]=#import_3b(j,i)
br_inform[begin..end,begin..end] = 0.02*inform[i,j]
dr_inform[begin..end,begin..end] = 0.02*inform[i,j]
{information totals}
d/dt(inform[begin..end,begin..end]) = br_inform[i,j] - dr_inform[i,j] + inmigration_inform[i,j]
{This is a table that converts the two-dimensional array inform to a single array that is used in the calculation of diffusion}
temp_inform[begin..end^2] = inform[1,i]
{This table is like a reverse ref_table. this will be indexed 1..inform_size. and each value of the array will hold the corresponding corrdinates to the ref_table. so rev_table[2] = 12..which will translate too inform 2 is at coordinates (1,2) on the ref_table}
temp_rev[begin..end,begin..end] = i*10 + j
rev_table[begin..end^2] = temp_rev[1,i]
{Calculate inmigration for each information
Each information DOESN'T contains an [i+x] factor from above when x is a multiple of the 10*i, so subtract out}
{Due to limiations in the ability of Madonna to perform REAL loops, modifications will be required to
this section of code as well as the section of code for the outmigration equations. the following terms will have to added/removed based on how many different informations you are dealing with.
TERM: migration[ref_table[i,j]+N]
Where N is the #inform * 10 (for outmigration N is just #information)
so if you added another set to this you would have 16 (4X4) so you would have to add up to
migration[ref_table[i,j]+160] and all terms in between}
inmigration_inform[begin..end,begin..end] = migration[ref_table[i,j]+10] + migration[ref_table[i,j]+20] + migration[ref_table[i,j]+30] + migration[ref_table[i,j]+40] + migration[ref_table[i,j]+50] + migration[ref_table[i,j]+60] + migration[ref_table[i,j]+70] + migration[ref_table[i,j]+80] + migration[ref_table[i,j]+90]
inmigration_inform[begin..end,begin..end] = inmigration_inform[i,j] - migration[ref_table[i,j] + 10*ref_table[i,j]]
{Calculate outmigration for each information
Each information DOESN'T contains an [i+x] factor from above when x is a multiple of the 10*i, so subtract out}
outmigration_inform[begin..end,begin..end] = migration[(ref_table[i,j]*10) + 1] + migration[(ref_table[i,j]*10) + 2] + migration[(ref_table[i,j]*10) + 3] + migration[(ref_table[i,j]*10) + 4] + migration[(ref_table[i,j]*10) + 5] + migration[(ref_table[i,j]*10) + 6] + migration[(ref_table[i,j]*10) + 7] + migration[(ref_table[i,j]*10) + 8] + migration[(ref_table[i,j]*10) + 9]
outmigration_inform[begin..end,begin..end] = outmigration_inform[i,j] - migration[ref_table[i,j] + 10*ref_table[i,j]]
{Migration Rates:
*migration between any two points is equal to a constatnt scalar times the inverse of the distance between the points squared.
*If the ones digit of Index is less than the tens digit then your distance variable will be indexed at ones and tens digit reversed 75 -> 57 and inform will be indexed at then tens digit 57 -> inform[5]
*if the ones digit of Index is greater than tens digit then distance is simply the index and inform index is tens digit.}
migration[11..(end^2)*11] = IF ((MOD(i,10) < INT(i /10)) AND (MOD(i,10) > 0)) THEN
.1 * (1/distance[MOD(i,10)*10 + INT(i/10)])*temp_inform[INT(i/10)]
ELSE IF (MOD(i,10) > 0) THEN
.1 * (1/distance[i])*temp_inform[INT(i/10)]
ELSE
0
distance[11..(end^2)*11] =IF(MOD(i,10) = 0 OR MOD(i,11) = 0) THEN 1
ELSE
SQRT((INT(rev_table[INT(i/10)]/10) - INT(rev_table[MOD(i,10)]/10))^2 + (MOD(rev_table[INT(i/10)],10) - MOD(rev_table[MOD(i,10)],10))^2)
%KqvY]
i1@rk4init_pop1i@$@
&8J\init_pop_else4@?
x-Qu`MbP?MbP?MbP?
]em &
,9.Fjnr
zAKaKKv-KK KK}K iK$N&N(O*
O,K.KO