Presentation1

3
Rg Function Rg[p_] := Module[{rgy, cm = {0, 0}, sum = 0}, For[x = 1, x <= Length[p], x++, cm[[1]] += p[[x]][[1]]; cm[[2]] += p[[x]][[2]]; ]; cm[[1]] = cm[[1]]/Length[p]; cm[[2]] = cm[[2]]/Length[p]; For[x = 1, x <= Length[p], x++, sum += EuclideanDistance[p[[x]], cm]^2; ];

Transcript of Presentation1

Page 1: Presentation1

Rg FunctionRg[p_] := Module[{rgy, cm = {0, 0}, sum = 0}, For[x = 1, x <= Length[p], x++, cm[[1]] += p[[x]][[1]]; cm[[2]] += p[[x]][[2]]; ]; cm[[1]] = cm[[1]]/Length[p]; cm[[2]] = cm[[2]]/Length[p]; For[x = 1, x <= Length[p], x++, sum += EuclideanDistance[p[[x]], cm]^2; ]; Return[Round[Sqrt[sum/Length[p]], 0.01]]]

Page 2: Presentation1

Main Code

Manipulate[SeedRandom[seed];

Module[{i = 0, nmax = max, pts = {{0, 0}}, path = {{0, 0}}, moves = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}, segments = {},

segLen, direction, pathway}, AppendTo[segments, seg1]; AppendTo[segments, seg2];

AppendTo[segments, seg3];

While[ i < nmax && Not@(And @@ (MemberQ [pts, #] & /@ Table[path[[-1]] + moves[[i]], {i, 1, 4}])),

Page 3: Presentation1

pathway = True;segLen = RandomChoice[segments];direction = RandomChoice[ Select[Table[moves[[i]], {i, 1, 4}], Not@MemberQ[pts, # + path[[-1]]] &]]; If[segLen == 1, (* Then *) i++; AppendTo[pts, path[[-1]] + direction]; AppendTo[path, path[[-1]] + direction], (* Else *) For[j = 1, j <= segLen && pathway, j++, If[MemberQ[pts, path[[-1]] + j*direction], pathway = False]]; If[pathway,

i++; For[k = 1, k <= segLen, k++, AppendTo[pts, path[[-1]] + k*direction]]; AppendTo[path, path[[-1]] + segLen*direction]]]];