Drunk on the way home!

6 Ansichten (letzte 30 Tage)
Abdulaziz Muslem
Abdulaziz Muslem am 3 Mai 2020
Kommentiert: Image Analyst am 10 Mai 2020
Drunk on the way home!
The drunk is halfway between home and pub, taking every step randomly in one direction. Write a function that will simulate a drunkard's movement. Its parameters will be the distance between home and pub and the number of steps to the drunken asleep (i.e. the maximum length of the simulation). The simulation ends either when the drunk arrives home or the pub, or after the number of steps has been exhausted.
Program format:
function drunkman_simulator(size,steps)
Output format:
>> drunkman_simulator(10, 100)
home . . . . . * . . . . pub
home . . . . * . . . . . pub
home . . . * . . . . . . pub
home . . . . * . . . . . pub
home . . . * . . . . . . pub
home . . . . * . . . . . pub
home . . . * . . . . . . pub
home . . * . . . . . . . pub
home . * . . . . . . . . pub
home . . * . . . . . . . pub
home . . . * . . . . . . pub
home . . * . . . . . . . pub
home . . . * . . . . . . pub
home . . * . . . . . . . pub
home . . . * . . . . . . pub
home . . . . * . . . . . pub
home . . . . . * . . . . pub
home . . . . * . . . . . pub
home . . . . . * . . . . pub
home . . . . * . . . . . pub
home . . . . . * . . . . pub
home . . . . . . * . . . pub
home . . . . . * . . . . pub
home . . . . . . * . . . pub
home . . . . . . . * . . pub
home . . . . . . . . * . pub
home . . . . . . . . . * pub
home . . . . . . . . * . pub
home . . . . . . . . . * pub
home . . . . . . . . . . pub
Arrived pub!
  10 Kommentare
Ing
Ing am 10 Mai 2020
I runned the code but It doesn't work. I couldn't understand why, because I didn't change anything from the atteched m file. It has to be working as I understand.
Image Analyst
Image Analyst am 10 Mai 2020
I just copied and pasted the test3.m I attached and it runs perfectly. I think you must have changed something. Please show your error message and attach the version you actually ran.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Image Analyst
Image Analyst am 3 Mai 2020
Bearbeitet: Image Analyst am 3 Mai 2020
OK. I assume it works because you didn't ask a question.
When I did this back in college they also asked us to find the probability distribution function for how far away from the starting point as a function of number of steps. I think it was eye opening for most students that the expected location is not right back at the starting location, especially since you could go +1 or -1 at each step.
For what it's worth, I'm attaching my set of random walk demos, in case anyone is interested in different random walk situations.

Weitere Antworten (0)

Kategorien

Mehr zu Descriptive Statistics finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by