Question
Revise the code of randomWalkPoints to have the entity go with equal probability in a N, S, E, or W direction. Hint: Choose the direction
Revise the code of randomWalkPoints to have the entity go with equal probability in a N, S, E, or W direction. Hint: Choose the direction based on the value of a random integer, 0, 1, 2, or 3. Please note the bolded.
function [lst] = randomWalkPoints(n) % RANDOMWALKPOINTS Function to produce a random walk, where at each time % step the entity goes diagonally in a NE, NW, SE, or SW direction, and to % return a list of the points in the walk % Pre: n is the number of steps in the walk. % Post: A list of the points in the walk has been returned. x = 0; y = 0; lst = zeros(n + 1,2); lst(1, :) = [0 0]; for i = 1:n if randi([0,1]) == 0 x = x + 1; else x = x - 1; end; if randi([0,1]) == 0 y = y + 1; else y = y - 1; end; lst(i + 1, :) = [x y]; end;
itled03.m | stepwi se.m X| graphs 1.m 1 monteCarloproject3.m randomwalkPoints.m X1 + function [1st] = randomwalkPoints(n) % RANDOMWALKPOINTS Function to produce a random walk, where at each time step the entity goes diagonally in a NE, NW, SE, or SW direction, and to % return a list of the points in the walk Pre: n is the number of steps in the walk. % Post: A list of the points in the walk has been returned. x=0 y=0 lst = zeros(n + 1,2); 1st(1, :) = [0 0]; for i 1:n if rand 1( [0,1]) = 0 x = x + 1; else x=x-1; end; if rand 1( [0,1]) = 0 y=y+1; else y=y-1; 1st(i + 1, :) = [x y]; end
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started