Drunk on the way home!
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Abdulaziz Muslem
el 3 de Mayo de 2020
Comentada: Image Analyst
el 10 de Mayo de 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 comentarios
Ing
el 10 de Mayo de 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
el 10 de Mayo de 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.
Respuesta aceptada
Image Analyst
el 3 de Mayo de 2020
Editada: Image Analyst
el 3 de Mayo de 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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Linear Algebra en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!