Gambler's Ruin in Matlab: Solving the Loop Problem

In summary, the conversation is about writing a program in Matlab for a gambler who starts with 5 dollars and bets 1 dollar each time. The house has favorable odds of 70/30. The person has made progress but is struggling with ending the loop when the gambler reaches 0. They have tried using a while loop but it did not work. The suggestion is to use [code] tags to show the code and the person is asking for help to implement the while loop.
  • #1
JohnPrior3
17
5
For Matlab, I need to write a program where a Gambler starts with 5 dollars and runs out with 1 dollar bets. The house has favorable odds of 70/30. I have gotten very far, but I can't find out how to end the loop when the gambler reaches 0. Here is my script:

Code:
A = 5

n=100;

x=rand(1,n);

    for i=1:n-1

        if x(i)>0.3

          A=A-1

        else

          A=A+1

        end
end

My script runs the 100 times and leaves me with a negative number. Everything works for the script, except ending at 0. I tried doing a while loop but it didn't work.
 
Last edited by a moderator:
Physics news on Phys.org
  • #2
The while loop is a better approach. Can you show that?

You can use [code] tags to make it easier to show code:

Code:
for i=1:n-1
  if x(i)>0.3
    A=A-1
 
  • #3
JohnPrior3 said:
For Matlab, I need to write a program where a Gambler starts with 5 dollars and runs out with 1 dollar bets. The house has favorable odds of 70/30. I have gotten very far, but I can't find out how to end the loop when the gambler reaches 0. Here is my script:

Code:
A = 5

n=100;

x=rand(1,n);

    for i=1:n-1

        if x(i)>0.3

          A=A-1

        else

          A=A+1

        end
end

My script runs the 100 times and leaves me with a negative number. Everything works for the script, except ending at 0. I tried doing a while loop but it didn't work.

So what you're saying is IF the gambler has no money, then he can't gamble??
 

FAQ: Gambler's Ruin in Matlab: Solving the Loop Problem

What is Gambler's Ruin in Matlab?

Gambler's Ruin is a mathematical concept that represents the probability of a gambler going bankrupt in a game of chance. In Matlab, it is commonly referred to as "Solving the Loop Problem" due to the use of loops in the code.

How does Matlab solve the Gambler's Ruin problem?

Matlab uses a loop-based algorithm to simulate multiple rounds of a game of chance and calculate the probability of going bankrupt. The loop continues until the desired number of simulations is reached, and the results are then analyzed to determine the likelihood of the gambler's ruin.

What inputs are required for solving the Loop Problem in Matlab?

The main inputs required for solving the Loop Problem in Matlab are the initial bankroll, the bet amount, and the probability of winning. These values can be adjusted to simulate different scenarios and analyze the potential outcomes of the game.

Can the Gambler's Ruin problem be solved without using loops in Matlab?

Yes, there are alternative methods for solving the Gambler's Ruin problem in Matlab, such as using vectorized operations or built-in functions. However, using loops is often the most straightforward and efficient approach.

How can the results of Gambler's Ruin in Matlab be interpreted?

The results of Gambler's Ruin in Matlab will provide the probability of going bankrupt for a given initial bankroll, bet amount, and win probability. This information can be used to make informed decisions in gambling or other scenarios involving risk and probability.

Similar threads

Replies
1
Views
1K
Replies
3
Views
1K
Replies
6
Views
2K
Replies
1
Views
1K
Replies
10
Views
2K
Replies
1
Views
1K
Replies
1
Views
2K
Back
Top