Skip to main content
added 4 characters in body; edited tags
Source Link
dr.blochwave
  • 8.8k
  • 3
  • 45
  • 78

I have these functions

Randomwalk1[n_] :=Accumulate[2*RandomInteger[{0, 1}, n] - 1]; Randomwalk2[n_] := NestList[# + 2*RandomInteger[{0, 1}] - 1 &, 0, n] 

that are random walks in 1D and I have to modify them to get a random walk in 2D, the walker can move right, left, step back or move forward with same probability 1/4 .. I'm a beginner and really don't know how to do that..

Thanks

I was thinking about an other way to do that without using these functions but I don't know if it can work and don't know how to do that in mathematica, here is the idea

if RandomInteger[{1,2}]=1RandomInteger[{1,2}]=1 the walker moves in x direction

and if RandomInteger[{1,2}]=2RandomInteger[{1,2}]=2 the walker moves in y direction

Then we call 2*RandomInteger[{0, 1}] - 12*RandomInteger[{0, 1}] - 1 to randomly generate -1 or +1 and the walker makes this step in the direction that was first determined

I have these functions

Randomwalk1[n_] :=Accumulate[2*RandomInteger[{0, 1}, n] - 1]; Randomwalk2[n_] := NestList[# + 2*RandomInteger[{0, 1}] - 1 &, 0, n] 

that are random walks in 1D and I have to modify them to get a random walk in 2D, the walker can move right, left, step back or move forward with same probability 1/4 .. I'm a beginner and really don't know how to do that..

Thanks

I was thinking about an other way to do that without using these functions but I don't know if it can work and don't know how to do that in mathematica, here is the idea

if RandomInteger[{1,2}]=1 the walker moves in x direction

and if RandomInteger[{1,2}]=2 the walker moves in y direction

Then we call 2*RandomInteger[{0, 1}] - 1 to randomly generate -1 or +1 and the walker makes this step in the direction that was first determined

I have these functions

Randomwalk1[n_] :=Accumulate[2*RandomInteger[{0, 1}, n] - 1]; Randomwalk2[n_] := NestList[# + 2*RandomInteger[{0, 1}] - 1 &, 0, n] 

that are random walks in 1D and I have to modify them to get a random walk in 2D, the walker can move right, left, step back or move forward with same probability 1/4 .. I'm a beginner and really don't know how to do that..

Thanks

I was thinking about an other way to do that without using these functions but I don't know if it can work and don't know how to do that in mathematica, here is the idea

if RandomInteger[{1,2}]=1 the walker moves in x direction

and if RandomInteger[{1,2}]=2 the walker moves in y direction

Then we call 2*RandomInteger[{0, 1}] - 1 to randomly generate -1 or +1 and the walker makes this step in the direction that was first determined

idea of programming this another way
Source Link

I have these functions

Randomwalk1[n_] :=Accumulate[2*RandomInteger[{0, 1}, n] - 1]; Randomwalk2[n_] := NestList[# + 2*RandomInteger[{0, 1}] - 1 &, 0, n] 

that are random walks in 1D and I have to modify them to get a random walk in 2D, the walker can move right, left, step back or move forward with same probability 1/4 .. I'm a beginner and really don't know how to do that..

Thanks

I was thinking about an other way to do that without using these functions but I don't know if it can work and don't know how to do that in mathematica, here is the idea

if RandomInteger[{1,2}]=1 the walker moves in x direction

and if RandomInteger[{1,2}]=2 the walker moves in y direction

Then we call 2*RandomInteger[{0, 1}] - 1 to randomly generate -1 or +1 and the walker makes this step in the direction that was first determined

I have these functions

Randomwalk1[n_] :=Accumulate[2*RandomInteger[{0, 1}, n] - 1]; Randomwalk2[n_] := NestList[# + 2*RandomInteger[{0, 1}] - 1 &, 0, n] 

that are random walks in 1D and I have to modify them to get a random walk in 2D, the walker can move right, left, step back or move forward with same probability 1/4 .. I'm a beginner and really don't know how to do that..

Thanks

I have these functions

Randomwalk1[n_] :=Accumulate[2*RandomInteger[{0, 1}, n] - 1]; Randomwalk2[n_] := NestList[# + 2*RandomInteger[{0, 1}] - 1 &, 0, n] 

that are random walks in 1D and I have to modify them to get a random walk in 2D, the walker can move right, left, step back or move forward with same probability 1/4 .. I'm a beginner and really don't know how to do that..

Thanks

I was thinking about an other way to do that without using these functions but I don't know if it can work and don't know how to do that in mathematica, here is the idea

if RandomInteger[{1,2}]=1 the walker moves in x direction

and if RandomInteger[{1,2}]=2 the walker moves in y direction

Then we call 2*RandomInteger[{0, 1}] - 1 to randomly generate -1 or +1 and the walker makes this step in the direction that was first determined

Source Link

Programming a 2D random walk

I have these functions

Randomwalk1[n_] :=Accumulate[2*RandomInteger[{0, 1}, n] - 1]; Randomwalk2[n_] := NestList[# + 2*RandomInteger[{0, 1}] - 1 &, 0, n] 

that are random walks in 1D and I have to modify them to get a random walk in 2D, the walker can move right, left, step back or move forward with same probability 1/4 .. I'm a beginner and really don't know how to do that..

Thanks