1

I've been trying to create a 2D random walk process for my project. The question is as follows, Create a 2-dimensional random walk process where the walker can move up, down, left, or right. The walker should have an equal chance of going in any direction (25%). Create a graph of a single walk.

We've been using these functions but I'm unsure how to go about it correctly.

`A = Table[0, {1}, {2}];
Do[
 x = RandomReal[];
 Which[
  x < 0.25, A[[i + 1, 1]] = A[[i, 1]] + 1;
  x < 0.25, A[[i + 1, 2]] = A[[i, 2]] - 1],
 {i, 1, 0}, {i, 1, 1}]
ListLinePlot[A]` 

It's supposed to look like this. Thanks

enter image description here

2
  • Perhaps you could draw inspiration from previously asked questions on this site (use the search bar at the top of the page). For instance, this question and its answers might be a good start: 2D random walk within a bounded area.
    – MarcoB
    Commented Apr 24, 2018 at 4:00
  • Okay, thank you. Commented Apr 25, 2018 at 3:23

1 Answer 1

4

For unbounded area, the following should work

ListLinePlot[Accumulate@RandomChoice[{{1, 0}, {-1, 0}, {0, 1}, {0, -1}}, 500]]
1

Not the answer you're looking for? Browse other questions tagged or ask your own question.