"* Write a program that contains a function to create data from a 2D random walk where we take 100 steps. \n",
"* Write a program that contains a function to create data from a 2D random walk where we take 5000 steps. \n",
" * Let each random walk start at (0,0), i.e., the first pair of values is $x=0, y=0$. \n",
" * Let each random walk start at (0,0), i.e., the first pair of values is $x=0, y=0$. \n",
" * Make the step size an optional parameter, the step size is fixed for a complete random walk.\n",
" * Make the step size an optional parameter, the step size is fixed for a complete random walk.\n",
" * Hint: Think about what the function should return.\n",
" * Hint: Think about what the function should return.\n",
...
@@ -25,7 +25,8 @@
...
@@ -25,7 +25,8 @@
"\n",
"\n",
"\n",
"\n",
"*Hint*: \\\n",
"*Hint*: \\\n",
"Think about which modules can help you so that your code is efficient and fast.\n",
"* Think about which modules can help you so that your code is efficient and fast.\n",
"* Numpy provides various random number generators in the sub-module ```np.random```\n",
"\n"
"\n"
]
]
}
}
...
...
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
# Random walk in two dimensions
# Random walk in two dimensions
A random walk is a sequence where decide randomly in which direction we can move. For example, in a one-dimensional random walk, we decide randomly if we move left or right.
A random walk is a sequence where decide randomly in which direction we can move. For example, in a one-dimensional random walk, we decide randomly if we move left or right.
We could take a coin, toss it and move right if it shows "head", or left if it shows "tail".
We could take a coin, toss it and move right if it shows "head", or left if it shows "tail".
Similarly, in a two-dimensional random walk, we need to decide if we move up, down, left, or right.
Similarly, in a two-dimensional random walk, we need to decide if we move up, down, left, or right.
In the simplest case, we aways take steps of the same length, but we could also vary our step size and take short, medium, or long steps.
In the simplest case, we aways take steps of the same length, but we could also vary our step size and take short, medium, or long steps.
### Exercise:
### Exercise:
* Write a program that contains a function to create data from a 2D random walk where we take 100 steps.
* Write a program that contains a function to create data from a 2D random walk where we take 5000 steps.
* Let each random walk start at (0,0), i.e., the first pair of values is $x=0, y=0$.
* Let each random walk start at (0,0), i.e., the first pair of values is $x=0, y=0$.
* Make the step size an optional parameter, the step size is fixed for a complete random walk.
* Make the step size an optional parameter, the step size is fixed for a complete random walk.
* Hint: Think about what the function should return.
* Hint: Think about what the function should return.
* Plot multiple random walks on top of each other. \
* Plot multiple random walks on top of each other. \
* Calculate the distance of between the start and the end of each random walk. \
* Calculate the distance of between the start and the end of each random walk. \
* For 200 random walks, create a histogram of the distribution of the distance.
* For 200 random walks, create a histogram of the distribution of the distance.
*Hint*: \
*Hint*: \
Think about which modules can help you so that your code is efficient and fast.
* Think about which modules can help you so that your code is efficient and fast.
* Numpy provides various random number generators in the sub-module ```np.random```