What Is the Probability of Winning in a Gambler's Ruin Scenario?

In summary, the conversation discusses a problem involving a gambler who starts with £1 and has a goal of reaching £100. The probability of winning and losing in the game is equal and the gambler must stop once they have no money remaining. The speaker is seeking guidance on how to use nested for loops to solve the problem using Matlab, but they only have limited experience with the program. Another suggestion is to use nested while loops instead.
  • #1
AASaunders
4
0
Hi guys, I have been given a problem to complete, but at the moment my progress has been minimal.

A gambler has £1 to gamble, he plays a game in which the probability of winning and losing are equal. If he wins he gains a pound, and loses a pound if he does not win. He starts with £1 and must stop once he has no money remaining. He has a goal of £100, if he achieve this he will stop and consider himself to have beat the casino. What is the probability of the gambler winning?

I have only had two classes on using Matlab since September, thus I am not very experienced.

To complete this problem I know I need to use nested For loops but I just don't know where to start, so any guidance would be appreciated very much.
 
Physics news on Phys.org
  • #2
Hello AASaunders,

I would say it would be easier with 2 nested "while" loops.

The outer one to make sure you get a few wins, the inner one to break free of the game once you lose or win.

J.
 

Related to What Is the Probability of Winning in a Gambler's Ruin Scenario?

1. What is a for loop in Matlab?

In Matlab, a for loop is a programming construct that allows you to execute a set of statements repeatedly for a given number of times. It is often used to iterate through data structures, such as arrays or matrices, and perform operations on each element.

2. How do I write a for loop in Matlab?

To write a for loop in Matlab, you first need to define the loop variable, which is typically denoted by the letter "i". Then, you specify the starting value, ending value, and increment/decrement for the loop variable. Finally, you add the statements to be executed inside the loop between the "for" and "end" keywords.

3. What is the difference between a for loop and a while loop in Matlab?

The main difference between a for loop and a while loop in Matlab is that a for loop executes a specific number of times, whereas a while loop executes until a certain condition is met. This condition is evaluated at the beginning of each iteration in a while loop, while in a for loop, the loop variable is incremented/decremented until the condition is met.

4. Can I nest for loops in Matlab?

Yes, you can nest for loops in Matlab. This means that you can have one for loop inside another for loop. This is often used when dealing with multi-dimensional arrays or when you need to perform multiple iterations over different sets of data.

5. How do I debug a for loop in Matlab?

To debug a for loop in Matlab, you can use the "dbstop" command to set breakpoints inside the loop. This will pause the execution of the loop at the specified breakpoints, allowing you to inspect the values of variables and troubleshoot any errors. You can also use the "fprintf" command to print out the values of certain variables at each iteration to track their changes.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
2
Views
3K
Replies
1
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
2
Views
4K
  • Programming and Computer Science
Replies
3
Views
1K
  • Calculus and Beyond Homework Help
Replies
14
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
5K
  • Set Theory, Logic, Probability, Statistics
Replies
24
Views
9K
  • Precalculus Mathematics Homework Help
Replies
12
Views
3K
Replies
12
Views
2K
  • Set Theory, Logic, Probability, Statistics
Replies
2
Views
3K
Back
Top