Question
Develop code as discussed in the section on Relationship between Number of Steps and Distance Covered to obtain a list of average distances covered for
Develop code as discussed in the section on Relationship between Number of Steps and Distance Covered to obtain a list of average distances covered for random walks of step sizes from 1 to 50. Then, using the data the program generates, do the analysis of Project 3.
Relationship between Number of Steps and Distance Covered
To discern a relationship between the number of steps, n, and average distance cov- ered in a random walk, we execute meanRandomWalkDistance(n, 100) for values of n from 1 to 50 and store each average distance in a list or array, listDist. Then, we employ the techniques of Module 8.3, Empirical Models, to determine the relationship.
function avgDist = meanRandomWalkDistance(n, numTests)
% RANDOMWALK Function to return average distance
% between first and last point in random walk of
% n steps, where the simulation is performed
% numTests number of times
sumDist = 0;
for j = 1:numTests
sumDist = sumDist + randomWalkDistance(n);
end;
function [dist] = randomWalkDistance(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: The distance from the starting point 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;
dist = sqrt(x^2 + y^2);
avgDist = sumDist/numTests;
%listDist = append(avgDist);
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