Drunk on the way home!

3 ビュー (過去 30 日間)
Abdulaziz Muslem
Abdulaziz Muslem 2020 年 5 月 3 日
コメント済み: Image Analyst 2020 年 5 月 10 日
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 件のコメント
Ing
Ing 2020 年 5 月 10 日
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 2020 年 5 月 10 日
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.

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2020 年 5 月 3 日
編集済み: Image Analyst 2020 年 5 月 3 日
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.
  1 件のコメント
Abdulaziz Muslem
Abdulaziz Muslem 2020 年 5 月 3 日
Thanks

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLinear Algebra についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by