Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

29- In a one-dimensional random walk the position x of a walker is computed by x

ID: 3540504 • Letter: 2

Question


29- In a one-dimensional random walk the position x of a walker is computed

by

xj = xj + s

where s is a random number. Write a Matlab program that calculates the number of

steps required for the walker to reach a boundary x =+-B(x= plus minus B)

Use MATLAB's built-in function randn(1,1) to calculate s.Run the program 100 times(by using a loop) and

calculate the average number of steps when B = 10.







In a one-dimensional random walk the position .v of a walker is computed by xj = xj + s where s is a random number. Write a program that calculates the number of steps required for the walker to reach a boundary v = plusminus B. Use MATLAB's built-in function random (1, 1) to calculate a. Run the program 100 times (by using a loop) and calculate the average number of steps when B = 10.

Explanation / Answer

% assumes x can be fractional as well

x=0;

B=10;

loop=100;

avgSteps=0;

for n=1:loop

xj=x;

steps=0;

while( abs(x-xj) < B)

s= randn(1,1);

xj = xj + s;

steps=steps+1;

end

avgSteps = avgSteps + steps;

end

avgSteps = avgSteps/loop;

fprintf('Average number of steps when B = %d, is %f ',B,avgSteps);



Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote