Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

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,
pocadF+pocadS:pocwbd *)


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];

 pocadF =

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

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

 pocadS = pocwbd - pocadF;

poc[1]= Join[pocwNbd, pocadF, pocadS];

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];

 pocadF =

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

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

 pocadS = pocwbd - pocadF;

poc[3]= Join[pocwNbd, pocadF, pocadS];

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];

 pocadF =

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

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

 pocadS = pocwbd - pocadF;

poc[Y+1]= Join[pocwNbd, pocadF, pocadS]

Y's initial value is 4, how can we repeat this loop until 20th step. I want to find poc[5],poc[7],poc[9] etc...

Osman Tuna


  • Prev by Date: Re: Integrate[], Sort[] and Hold[]
  • Next by Date: graph recursion of a cube sort
  • Previous by thread: Re: laptop recommendation to run mathematica fast?
  • Next by thread: graph recursion of a cube sort