For class today we attempted to use Mathematica to come up with a simple code to write a random path with the use of probabilities. This is the code Gary, Matt and I came up with:
(*This makes the first step of the random path.*)
randompath = {{0, 0}};
(*This defines the neighbors of the point{x,y}.*)
left[{x_, y_}] := {x – 1, y};
right[{x_, y_}] := {x + 1, y};
up[{x_, y_}] := {x, y + 1};
down[{x_, y_}] := {x, y – 1};
lasteightsites = randompath[[-Min[{Length[randompath], 8}] ;; -1]];
neighbors[{x_, y_}] := {left[{x, y}], right[{x, y}], up[{x, y}],
down[{x, y}]};
beenthere[{x_, y_}] := Intersection[neighbors , lasteightsites];
p = If[Length[beenthere[{x, y}]] == 4, 0,
1/(4 – Length[beenthere[{x, y}]])];
basically the code start out at the point (0, 0).
Then define (x, y) for the four neighboring points. (left, right, up, and down)
After defining the neighboring points we have to come up with a code that defines the last eights sites visited in the walk and then we intersect those points with the neighboring points. This gives us the values of the (x, y) we have been in the random walk.
The probability of the random walk is 1/ 4 -the length of the been there (x,y) values.