1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matlab Gambler's Ruin

  1. Feb 18, 2015 #1
    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 (Text):

    A = 5



        for i=1:n-1

            if x(i)>0.3




    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: Feb 18, 2015
  2. jcsd
  3. Feb 18, 2015 #2


    User Avatar
    2016 Award

    Staff: Mentor

    The while loop is a better approach. Can you show that?

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

    Code (Text):
    for i=1:n-1
      if x(i)>0.3
  4. Feb 19, 2015 #3


    User Avatar
    Gold Member

    So what you're saying is IF the gambler has no money, then he cant gamble??
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted

Similar Discussions: Matlab Gambler's Ruin
  1. MATLAB "for loops" (Replies: 8)

  2. Matlab Eigenvectors (Replies: 2)

  3. Matlab palindrome (Replies: 3)

  4. Matlab Graphing (Replies: 1)