Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

C++ Database Development

Authors: Al Stevens

1st Edition

1558283579, 978-1558283572

Students also viewed these Databases questions

Question

What kind of problem is this? How do I know?

Answered: 1 week ago

Question

Identify three ways to manage an intergenerational workforce.

Answered: 1 week ago

Question

Prepare a Porters Five Forces analysis.

Answered: 1 week ago

Question

Analyze the impact of mergers and acquisitions on employees.

Answered: 1 week ago