The Use of Matlab to Solve the Question! Tyvm :D When zombies roam the earth, it
ID: 701443 • Letter: T
Question
The Use of Matlab to Solve the Question! Tyvm :D
When zombies roam the earth, it is useful to predict their movements. A zombie that is awake (and not chasing after human) exhibits what is termed ‘random walk. The position x of a random-walker is computed by where s is a random number. Write a program that calculates the number of steps required for a captured walker to reach a fence boundary x = 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=10Explanation / Answer
Code:
clear
for j=1:100
x=0;
i=0;
while 1
i=i+1;
x=x+randn(1,1);
if 9.995<=abs(x) && abs(x)<=10.005
break
end
end
steps(j)=i;
end
average_steps = sum(steps)/100
------
Here, i have included a tolerance of 0.005 meters so that any value between 9.995 and 10.005 would be counted.
Also, this is to note that due to such long itertaions, the code takes a very long time to execute.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.