Monte Carlo stimulation about gamble

I got a problem about writing the code of this question:
A gambler plays a sequence of fair games against an adversary in which the probability that the gambler wins $1 on any given game is 0.5 . We assume that initially the gambler has $5 and his adversary has $12. The game goes on until either of the players runs out of money, since no credit is allowed. If gambler runs out of money first, we say that he has been ruined. Write a computer program to simulate the sequence of games until one of the players is ruined.
Thx

Antworten (2)

Image Analyst
Image Analyst am 27 Okt. 2015

0 Stimmen

My Monte Carlo and random walk demos, attached, might help.
Thorsten
Thorsten am 27 Okt. 2015
Bearbeitet: Thorsten am 27 Okt. 2015

0 Stimmen

You can use this code
money = [5 12];
while ~any(money == 0)
player1wins = rand(1,1) > 0.5;
if player1wins
money = money + [1 -1];
else
money = money + [-1 1];
end
money
end

4 Kommentare

Alisha Pennington
Alisha Pennington am 2 Mär. 2017
How would you run 500 simulations of this game?
Put it in a loop that executes 500 times
for experiment = 1 : 500
% Code to do one experiment....
end
See my demos attached in my answer.
Angelika Ghazale
Angelika Ghazale am 13 Feb. 2022
ho can i plot this as a function of time?
Image Analyst
Image Analyst am 13 Feb. 2022
@Angelika Ghazale how is the time variable being determined? By calling now(), or toc()?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Card games finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 27 Okt. 2015

Kommentiert:

am 13 Feb. 2022

Community Treasure Hunt

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

Start Hunting!

Translated by