# Where I need put values in my code to generate the result that I want

Posted 8 years ago
10783 Views
|
5 Replies
|
0 Total Likes
|
 I'm doing a project about random walks, but I don't find where put values from n and t to give me the result that I want Meander[n_, t_] := Module[{RND, walk, VonNeumann, initConf}, RND := Random[Integer, {1, 4}]; initConf = ReplacePart[Table[0, {2 n + 1}, {2 n + 1}], RND, {n + 1, n + 1}]; walk[1, 0, 0, 0, 0] := 0; walk[2, 0, 0, 0, 0] := 0; walk[3, 0, 0, 0, 0] := 0; walk[4, 0, 0, 0, 0] := 0; walk[0, 3, 0, 0, 0] := RND; walk[0, 0, 4, 0, 0] := RND; walk[0, 0, 0, 1, 0] := RND; walk[0, 0, 0, 0, 2] := RND; walk[0, 1, 0, 0, 0] := 0; walk[0, 2, 0, 0, 0] := 0; walk[0, 4, 0, 0, 0] := 0; walk[0, 0, 1, 0, 0] := 0; walk[0, 0, 2, 0, 0] := 0; walk[0, 0, 3, 0, 0] := 0; walk[0, 0, 0, 2, 0] := 0; walk[0, 0, 0, 3, 0] := 0; walk[0, 0, 0, 4, 0] := 0; walk[0, 0, 0, 0, 1] := 0; walk[0, 0, 0, 0, 3] := 0; walk[0, 0, 0, 0, 4] := 0; walk[0, 0, 0, 0, 0] := 0; VonNeumann[func_, lat_] := MapThread[func, Map[RotateRight[lat, #] &, {{0, 0}, {1, 0}, {0, -1}, {-1, 0}, {0, 1}}], 2]; NestList[VonNeumann[walk, #] &, initConf, t] ] 
5 Replies
Sort By:
Posted 8 years ago
 Hi Camilo,So, it looks like the numbers are the directions to move. But if you are going for a graphic, all you really need is a position in the matrix.Instead of using 0 for the entries that don't count, I used 0.0 so that I can distinguish the position of the newly generated move by looking for an Integer.Then I generated a graphic of each of the moves by drawing a line from each move to the next.I'm not very advanced, functional programming-wise, so I used a Do loop. Meander[n_, t_] := Module[{RND, walk, VonNeumann, initConf}, RND := Random[Integer, {1, 4}]; initConf = ReplacePart[Table[0.0, {2 n + 1}, {2 n + 1}], RND, {n + 1, n + 1}]; walk[1, 0.0, 0.0, 0.0, 0.0] := 0.0; walk[2, 0.0, 0.0, 0.0, 0.0] := 0.0; walk[3, 0.0, 0.0, 0.0, 0.0] := 0.0; walk[4, 0.0, 0.0, 0.0, 0.0] := 0.0; walk[0.0, 3, 0.0, 0.0, 0.0] := RND; walk[0.0, 0.0, 4, 0.0, 0.0] := RND; walk[0.0, 0.0, 0.0, 1, 0.0] := RND; walk[0.0, 0.0, 0.0, 0.0, 2] := RND; walk[0.0, 1, 0.0, 0.0, 0.0] := 0.0; walk[0.0, 2, 0.0, 0.0, 0.0] := 0.0; walk[0.0, 4, 0.0, 0.0, 0.0] := 0.0; walk[0.0, 0.0, 1, 0.0, 0.0] := 0.0; walk[0.0, 0.0, 2, 0.0, 0.0] := 0.0; walk[0.0, 0.0, 3, 0.0, 0.0] := 0.0; walk[0.0, 0.0, 0.0, 2, 0.0] := 0.0; walk[0.0, 0.0, 0.0, 3, 0.0] := 0.0; walk[0.0, 0.0, 0.0, 4, 0.0] := 0.0; walk[0.0, 0.0, 0.0, 0.0, 1] := 0.0; walk[0.0, 0.0, 0.0, 0.0, 3] := 0.0; walk[0.0, 0.0, 0.0, 0.0, 4] := 0.0; walk[0.0, 0.0, 0.0, 0.0, 0.0] := 0.0; VonNeumann[func_, lat_] := MapThread[func, Map[RotateRight[lat, #] &, {{0.0, 0.0}, {1, 0.0}, {0.0, -1}, {-1, 0.0}, {0.0, 1}}], 2]; NestList[VonNeumann[walk, #] &, initConf, t]] out = Meander[6, 126]; bb = {}; Do[ AppendTo[bb, Position[out[[d, All]], _Integer]], {d, 1, 127}]; Graphics[Line[Flatten[bb, 1]]] It looks as though your random walk is actually on a torus connected left-to-right and top-to-bottom. That would be interesting to draw!Eric
Posted 8 years ago
 Hi Camilo,I'm beginning to see why you wanted NestList; is it so that you can see the progression of the walk?Here are the individual parts summed into one: Meander[n_,t_]:=Module[{RND,walk,VonNeumann,initConf,out,m},RND:=Random[Integer,{1,4}]; initConf=ReplacePart[Table[0,{2 n+1},{2 n+1}],RND,{n+1,n+1}]; walk[1,0,0,0,0]:=0; walk[2,0,0,0,0]:=0; walk[3,0,0,0,0]:=0; walk[4,0,0,0,0]:=0; walk[0,3,0,0,0]:=RND; walk[0,0,4,0,0]:=RND; walk[0,0,0,1,0]:=RND; walk[0,0,0,0,2]:=RND; walk[0,1,0,0,0]:=0; walk[0,2,0,0,0]:=0; walk[0,4,0,0,0]:=0; walk[0,0,1,0,0]:=0; walk[0,0,2,0,0]:=0; walk[0,0,3,0,0]:=0; walk[0,0,0,2,0]:=0; walk[0,0,0,3,0]:=0; walk[0,0,0,4,0]:=0; walk[0,0,0,0,1]:=0; walk[0,0,0,0,3]:=0; walk[0,0,0,0,4]:=0; walk[0,0,0,0,0]:=0; VonNeumann[func_,lat_]:=MapThread[func,Map[RotateRight[lat,#]&,{{0,0},{1,0},{0,-1},{-1,0},{0,1}}],2]; out=NestList[VonNeumann[walk,#]&,initConf,t]; Sum[out[[m]],{m,1,t+1}]//MatrixForm] Maybe Sum isn't what you want. Not sure what the numbers mean.Eric
Posted 8 years ago
 Hi Camilo,I'm not quite sure what Meander is supposed to do, but if you change the NestList to Nest, you'll only show the last of the Nested calculation, not the whole list. Then if you use Meander[n,t]//MatrixForm, you can see the entry that was generated for each call.This might not be what you are aiming for. A little description of Meander would be helpful.Eric
Posted 8 years ago
 Could it be that you've forgotten the blanks in the function arguments? Try Meander[n_, t_] := and VonNeumann[func_, lat_] := Eric
Posted 8 years ago
 Thank you Eric, I put it and show me the output but now I have a new question, can you explain why generate a matrix output?
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.