Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

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...

1 answer below »
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
Answered 4 days After Oct 03, 2021

Solution

Dr. Purnima Kumari answered on Oct 05 2021
117 Votes
Random Walk assignment
MATH 210-01, Fall 2021
Ryan Pellico, Department of Mathematics, Trinity College
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.
Solution Code:
Function: three_d_walk
function [x,y,z] = three_d_walk(num_steps)
% This function performs a three-dimensional random walk in the xyz-plane of
% length num_steps (a positive integer),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 column vectors x, y and z will record the sequences of coordinates the
% walker encounters on the walk.
x = zeros(num_steps+1,1);
y = zeros(num_steps+1,1);
z = zeros(num_steps+1,1);
% (x0,y0,z0) are the coordinates of the starting point for the random walke
% in the plane
x0 = 0;
y0 = 0;
z0 = 0;
x(1) = x0;
y(1) = y0;
z(1) = z0;
for n = 1:num_steps
roll = randi(6);

if roll == 1 % if the roll is a 1, take a step UP
x(n+1) = x(n);
y(n+1) = y(n) + 1;
z(n+1) = z(n);
elseif roll == 2 % if the roll is a 2, take a step DOWN
x(n+1) = x(n);
y(n+1) = y(n) - 1;
z(n+1) = z(n);
elseif roll == 3 % if the roll is a 3, take a step LEFT
x(n+1) = x(n) - 1;
y(n+1) = y(n);
z(n+1) = z(n);
elseif roll == 4 % if the roll is a 4, take a step RIGHT
x(n+1) = x(n) + 1;
y(n+1) = y(n);
z(n+1) = z(n);
elseif roll == 5 % if the roll is a 5, take a step FRONT
x(n+1) = x(n);
y(n+1) = y(n);
z(n+1) = z(n)+1;
elseif roll == 6 % if the roll is a 6, take a step BACK
x(n+1) = x(n);
y(n+1) = y(n);
z(n+1) = z(n)-1;
end

end
Function:...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here