Re: lattice definition: help
- To: mathgroup@smc.vnet.net
- Subject: [mg11189] Re: lattice definition: help
- From: gaylord@ux1.cso.uiuc.edu (richard j. gaylord)
- Date: Mon, 2 Mar 1998 23:10:46 -0500
- Organization: university of illinois
- References: <6d0ch7$2no@smc.vnet.net>
In article <6d0ch7$2no@smc.vnet.net>, Christofer Edling <cedling@sociology.su.se> wrote: > I would be most grateful if someone could help me with this one. I've > tried to solve the problem with the "Table" function without much > success. > > I wish to generate an n*n lattice with the following characteristics: > > 1. Each cell in the lattice can be in one out of three possible states, > i.e. A,B,C. > 2. The distribution of states across the whole lattice is defined by > user input, i.e. 30% A's, 20% B's, 50% C's. 3. Given the defined > distribution, each cell in the lattice should be randomly assigned a > state (A,B or C). > > Any suggestions appreciated, > Christofer > (cedling@sociology.su.se) here's a way to do it. i've given the answer for 4 states instead in of 3 becuase i just took the code from my new simulation book [coming out in june] ============================ 1 = state A 2 = state B 3 = state C 4 = state D {s, t, u, v} - probability of being in state A, B, C, D In[6]:= s = 0.30; t = 0.20; u = 0.50; v = 0; In[7]:= n = 100; lat = Table[1, {n}, {n}] /. 1 :> Floor[1 + v + u + Random[]] /. {1 :> Floor[1 + t/(s + t) + Random[]], 2 :> Floor[3 + v/(v + u) + Random[]]}; N[Count[Flatten[lat], 1]/n^2] Out[10]= 0.3056 N[Count[Flatten[lat], 2]/n^2] Out[11]= 0.2081 N[Count[Flatten[lat], 3]/n^2] Out[12]= 0.4863 -- richard j. gaylord, university of illinois, gaylord@uiuc.edu "What I cannot create, I do not understand" -Richard P. Feynman-