Random Walk assignment
MATH 210-01, Fall 2021
Ryan Pellico, Department of Mathematics, Trinity College
In class we used two_d_walk_UDLR(num_steps) and two_d_walk_angle(num_steps) to perform
“UDLR" and “angle" random walks of length num_steps. Both functions return the column vectors
[x, y] of coondinates encourntered on the walk. Note that the lengths of x and y are num_steps +
1.
The script visualize_walks performs each of the above random walks one time and plots the
esults in a figure using the plot() and scatter() functions. An example is shown below fo
num_steps = 10000.
Additionally, we used the function distance_of_walkers(num_sims,num_steps) to repeatedly
(num_sims times) run UDLR and angle walks of length num_steps and calculate the final distances
from the starting point in the column vectors [distances_UDLR, distances_angle], each of which
has length num_sims+1.
Using the script distribution_of_distances(), we studied the distribution of distances for each
type of random walk. An example is shown below for num_steps = 1000 and num_sims = 10000
1
1. (30 points) Create a new function three_d_walk(num_steps) that performs a 3-dimensional
andom walk of length num_steps, by starting at the origin (x, y, z) = (0, 0, 0) and rolling a fair 6-
sided die to determine the direction of each step (up, down, left, right, front, back). The function
should return the column vectors [x, y, z] which record the coordinates of each step of the
walk.
Hint: use the two_d_walk_UDLR(num_steps) function as a template.
2. (20 points) Create a new script visualize_3_d_walk that calls your function in 1. and uses
the plot3() and scatter3() functions to visualize the results of a 3-dimensional walk of 10, 000
steps.
Hint: use the visualize_walks script as a template.
3. (40 points) Write a script average_distance_plot that uses the distance_of_walkers()
function to perform 10, 000UDLR and angle walks of length num_steps for each value of num_steps
in the list 10:10:1000, and returns the average distance from the origin in column vectors
averages_UDLR and averages_angle.
Your script should also plot the resulting averages against the vector 10:10:1000 on the same
axis. Use a red solid line with square markers for the UDLR averages, and a blue solid line with
circle markers for the angle average. Include a legend, label your axes appropriately, and include
a descriptive title.
4. (10 points) Using the graph in 3., hypothesize about the functional relationship between the
number of steps in a walk and the average distance of the walker from the starting point. Does
the relationship seem to depend on which type of walk (UDLR or angle) is performed?
2