MathGroup Archive 2006

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

Search the Archive

Code problem

  • To: mathgroup at smc.vnet.net
  • Subject: [mg65574] Code problem
  • From: "Eoin Gleeson" <twelvety at gmail.com>
  • Date: Sat, 8 Apr 2006 00:45:18 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Dear Group,

I am trying to execute the model below in Mathematica 5.2 (student),
but no matter what values I input for the initial conditions, the
output values for ST and T fail to change. I wonder if anyone would be
so good as to have a look at where I am going wrong with the code? Or
even suggest an appropriate forum to pursue this problem.

Kind regards,
Eoin Gleeson
Trinity College Dublin

In[1]:=

Clear[PopSize];
Clear[Wealth]
Clear[Iteration];
Clear[SampleSize];
Clear[Cost];
Clear[Benefit];
Clear[Tol];

PopSize = 100;
Iteration =20;
SampleSize = 10;
Cost = 1;
Benefit = SampleSize;
Tol = 8;
Tol2 =3;

Wealth = Table [1, {PopSize}];
Clear[Status]
Status = Table [0, {PopSize}];
Clear[PopString]
PopString = Table[Random[], {PopSize}];
Return["Initial Wealth"]
Return[Wealth]
Return["Initial Status"]
Return[Status]


Do[

  {Clear[a];
    a = Table[Random[Integer, {1, PopSize}], {SampleSize}];
    Clear[S];
    S = Table[Status[[a[[m]]]], {m, 1, SampleSize}];
    Clear[ST];
    SS = SampleSize*SampleSize;
    ST=Table[0,{ SS}];
    For[i=1, i<SampleSize+1, i++, {For[j=1, j<Samplesize+1, j++,
          {For[k=0, k<SS+1, k++, ST[[k]]=S[[i]]-S[[j]]]}]}];
    Clear[T];
    T=0;
    For[j=0,j<SS+1, j++,{If[ST[[j]]<Tol2, T++]}];
    For[i=1, i<SampleSize+1, i++,
      {If[T>Tol+Tol+2,

                {If[Status[[a[[i]]]]â? 5, Status[[a[[i]]]]++],
                  Wealth[[a[[i]]]] = Wealth[[a[[i]]]] - Cost +Benefit},


               {If[Status[[a[[i]]]]â?  -5, Status[[a[[i]]]]--]}
           ]}]
    }, {Iteration}]
Return["ST"]
Return[ST]
Return["T"]
Return[T]
Return["Final Wealth"]
Return[Wealth]
Return["Final Status"]
Return[Status]



Out[20]=
Return[Initial Wealth]

Out[21]=
Return[{1,1,1,

1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,

1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}]

Out[22]=
Return[Initial Status]

Out[23]=
Return[{0,0,0,

0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}]

Out[25]=
Return[ST]

Out[26]=
Return[{0,0,0,

0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}]

Out[27]=
Return[T]

Out[28]=
Return[100]

Out[29]=
Return[Final Wealth]

Out[30]=
Return[{19,19,

1,28,1,10,1,37,10,19,19,1,28,1,10,28,1,10,1,28,10,19,19,28,10,46,55,10,
    19,28,10,37,19,46,10,46,37,10,

1,28,10,28,19,19,28,10,10,19,10,37,10,28,19,28,19,19,10,28,28,1,10,10,10,

19,19,28,19,19,10,46,28,37,10,19,19,10,37,28,10,10,19,37,1,28,19,1,19,
    28,19,28,19,19,10,10,1,28,19,37,1,19}]

Out[31]=
Return[Final Status]

Out[32]=
Return[{2,2,0,

3,0,1,0,4,1,2,2,0,3,0,1,3,0,1,0,3,1,2,2,3,1,5,5,1,2,3,1,4,2,5,1,5,4,1,0,3,

1,3,2,2,3,1,1,2,1,4,1,3,2,3,2,2,1,3,3,0,1,1,1,2,2,3,2,2,1,5,3,4,1,2,2,1,
    4,3,1,1,2,4,0,3,2,0,2,3,2,3,2,2,1,1,0,3,2,4,0,2}]


  • Prev by Date: Problem with compiled function (is this a bug?)
  • Next by Date: Re: 64-bit GraphPlot problem
  • Previous by thread: Re: Problem with compiled function (is this a bug?)
  • Next by thread: Re: Code problem