Looping- Programming

• To: mathgroup at smc.vnet.net
• Subject: [mg101017] Looping- Programming
• From: Osman Tuna <osmantunagokgoz at yahoo.com>
• Date: Sun, 21 Jun 2009 07:04:25 -0400 (EDT)
• Organization: The Math Forum

```We want to make a demonstration about population and cities. Firstly we chose an initial condition, let's say we have 5 cities with population {1000,300,7000,60,550} respectively. After that we give a decision population growth rate with selection random number. After we find new population of cities we decide whether a city divide or not, and how they will divide. We again give a random number to these cities population,
and if this random number  0.0<=x<=0.1 it will divide, if 0.1<x<=1.0 it will not divide. We decided which ones will be divided, now we decide how they divide, again select random number for cities -we know that they divide- and cross these random number and cities population. So at the end of this process our number of cities increase and our total population increase. But now we want to repeat this process again and again until 20th process. And we can see how we will have cities and population with our world model. I have studied on this demonstration, I success to write code for one process but I can't make the repetition of these processes until 20th step.

(*poc: population of cities,
cwbd: cities will be divided,
cwNbd: cities will NOT be divided,
pocwbd: population of cwbd
pocwNbd:population of cwNbd,

poc[0]  = {1000,300,7000,60,550};

s= Table[Random[], {Count[poc[0], _Integer]}];

p = Partition[Riffle[s, poc[0]], 2];

cwbd = Cases[p, {x_, y_} /; 0.0 <= x <= 0.1];

cwNbd = Cases[p, {x_, y_} /; 0.1 < x <= 1.0];

pocwbd = Cases[cwbd, {x_, y_} -> y];

pocwNbd = Cases[cwNbd, {x_, y_} -> y];

IntegerPart[Cases[cwbd, {x_, y_} -> y]*

Table[Random[], {Count[pocwbd, _Integer]}]];

poc[2]=poc[1]+poc[1]*IntegerPart [Table[Random[],{Count[poc[1],_Integer]}]];

s= Table[Random[], {Count[poc[2], _Integer]}];

p = Partition[Riffle[s, poc[2]], 2];

cwbd = Cases[p, {x_, y_} /; 0.0 <= x <= 0.1];

cwNbd = Cases[p, {x_, y_} /; 0.1 < x <= 1.0];

pocwbd = Cases[cwbd, {x_, y_} -> y];

pocwNbd = Cases[cwNbd, {x_, y_} -> y];

IntegerPart[Cases[cwbd, {x_, y_} -> y]*

Table[Random[], {Count[pocwbd, _Integer]}]];

poc[Y]=poc[Y-1]+IntegerPart[poc[Y-1]*Table[Random[],{Count[poc[Y-1],_Integer]}]];

s= Table[Random[], {Count[poc[Y], _Integer]}];

p = Partition[Riffle[s, poc[Y]], 2];

cwbd = Cases[p, {x_, y_} /; 0.0 <= x <= 0.1];

cwNbd = Cases[p, {x_, y_} /; 0.1 < x <= 1.0];

pocwbd = Cases[cwbd, {x_, y_} -> y];

pocwNbd = Cases[cwNbd, {x_, y_} -> y];

IntegerPart[Cases[cwbd, {x_, y_} -> y]*

Table[Random[], {Count[pocwbd, _Integer]}]];