Re: lattice definition: help
- To: mathgroup@smc.vnet.net
- Subject: [mg11208] Re: lattice definition: help
- From: Rolf Mertig <rolf@mertig.com>
- Date: Mon, 2 Mar 1998 23:11:00 -0500
- Organization: Mertig Research & Consulting
- References: <6d0ch7$2no@smc.vnet.net>
One possibility is:
Options[Lattice] = {States -> {A, B, C}}; (* The first and second
argument are the percentage of the first state, given as reals; n is
the size of the lattice *) Lattice[ia_Real, ib_Real, n_Integer,
opts___Rule] :=
Module[{nn = n^2, a, b, c, stats},
Needs["DiscreteMath`Combinatorica`"];
stats = States /. {opts} /. Options[Lattice]; {a, b} =
Round[{ia*nn, ib*nn}];
c = nn - a - b; Partition[Join[Table[stats[[1]], {a}],
Table[stats[[2]], {b}],
Table[stats[[3]],{c}]][[ToExpression["RandomPermutation"][nn]]],n]
]/;(ia+ib<=1.);
(* This is not necesary, but makes nice colored circles in a Notebook
... *)
MakeBoxes[A, _] :=
InterpretationBox[StyleBox["\[FilledCircle]",
FontColor-> RGBColor[1, 0, 0]], A]; MakeBoxes[B, _] :=
InterpretationBox[StyleBox["\[FilledCircle]",
FontColor-> RGBColor[0, 1, 0]], B]; MakeBoxes[C, _] :=
InterpretationBox[StyleBox["\[FilledCircle]",
FontColor-> RGBColor[0, 0, 1]], C]; (* This is your example:
30% A's, 20% B's, and take n = 22 *) Lattice[0.3, 0.2, 22]
Rolf Mertig
http://www.mertig.com
Christofer Edling 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)