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!

Homework Help: Gambler's ruin

  1. Apr 8, 2016 #1
    1. The problem statement, all variables and given/known data
    I ask for help in solving the exercises in this project on applied linear algebra. The problem outlined in the project is one in which we are tasked with modeling the demise of a gambler.

    I need help solving exercise 1 (in red) on page 6. I have pasted the exercise text into the text body below, in block quotes.

    Using the equations discussed above, evaluate numerically U(l) as a function of the initial gambler position l. Use e.g. M = 100 or similar. This is the code that I have written

    M = 100;

    X = ones(M,1); A = diag(-2*X,0); clear X X = ones(M-1,1); B = diag(X,1); C = diag(X,-1); T = A+B+C;

    tau = 1; N = -(inv(T)/tau)*n0 n0 = eye;

    numeric::int(N, l = 0..infinity)

    2. Relevant equations


    3. The attempt at a solution
     
  2. jcsd
  3. Apr 8, 2016 #2

    SteamKing

    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

    There's no attachment or image pasted into the OP. The details of the problem are not clear.
     
  4. Apr 8, 2016 #3
    Thanks for pointing it out!

    https://onedrive.live.com/redir?resid=6AFDD76B502B7B9C!4262&authkey=!AM2th-5i26TrCcI&ithint=file%2Cpdf [Broken]
     
    Last edited by a moderator: May 7, 2017
  5. Apr 9, 2016 #4
    Progress (and bump)

    clear
    M=10;
    X = ones(M,1);
    A = diag(-2*X,0);

    clear X
    X = ones(M-1,1);
    B = diag(X,1);
    C = diag(X,-1);
    T = A+B+C;
    clear X B C; % remove these matrices from memory

    n0 = randi([1 M-1],1); % Initial gambler position, determined using a random seed generator

    tau = 365

    N = -inv(T)/tau * n0 % The ultimate probability of Gambler's ruin. R(l) = N(l)
     
    Last edited: Apr 9, 2016
  6. Apr 10, 2016 #5
    I can't make sense of what I must do to solve the exercise
     
  7. Apr 10, 2016 #6

    Ray Vickson

    User Avatar
    Science Advisor
    Homework Helper

    I can't make sense of the gambler's ruin problem as presented in the pdf file you attached. I know the gambler's ruin problem, and none f the versions I have seen have involved continuous time systems and differential equations. It seems like the author of the pdf wants you to treat the time between gambles as exponentially-distributed random variables, so you get a differential equation for the probability of "position" as a function of time. However, that is not involved with computing the probability of ruin.
     
  8. Apr 11, 2016 #7

    haruspex

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member

    No, the model is small gambles at very short equal intervals, making it effectively a continuous process.
     
  9. Jul 26, 2016 #8
    Yes thay's correct.

    Should I be getting a greater than 1 chance of gambler's ruin occurring as a function of initial position?

    I'm talking about this exercise:
    • Using the equations discussed above, evaluate numerically U(l) as a function of the initial gambler position l. Use e.g. M = 100 or similar

    My code
    clear
    M=4;
    X = ones(M,1);
    A = diag(-2*X,0);
    clear X
    X = ones(M-1,1);
    B = diag(X,1);
    C = diag(X,-1);
    T = A+B+C;

    tau=1; %For simplicity, we take tau = 1
    n0=zeros(1,M)';
    n0(1)=1; % Initial position is taken to be 1
    ulP=-(inv(T)/tau)*n0;
    plot(ulP,'r*');
     
  10. Jul 26, 2016 #9

    Ray Vickson

    User Avatar
    Science Advisor
    Homework Helper

    No, you should never, ever, get a probability > 1 for anything, ruin or otherwise. Sometimes, though, when you use approximate solution techniques and finite-wordlength floating-point computations you can have probabilities that exceed 1 slightly.

    I do not understand your code, so have no way of assessing what you have done and where the errors (if any) arise. You do not even tell use what software you are using!
     
  11. Jul 26, 2016 #10
    I should mention that I use matlab.
     
  12. Jul 26, 2016 #11

    haruspex

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member

    Is that valid? The file you attached does not explain what tau is, but it smells like a normalisation factor, i.e. its function is to ensure the probabilities of all the mutually exclusive events add up to 1.
     
  13. Jul 26, 2016 #12
    Tau determines the rate at which ultimate ruin is reached. It can be of any magnitude, i.e. seconds, months or years.
     
  14. Jul 26, 2016 #13

    haruspex

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member

    Then shouldn't its value affect the elements of T?
    As a check, try varying tau. If I read your code correctly, the calculated probability will vary inversely. That would clearly indicate a problem.
     
  15. Jul 27, 2016 #14
    Varying tau varies the calculated probability inversely.
     
  16. Jul 27, 2016 #15

    haruspex

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member

    Right, so you cannot arbitrarily plug in tau=1. I would think there is a relationship between tau and T.
     
  17. Jul 27, 2016 #16
    The project description doesn't mention anything about the relationship. By the way, I was informed that tau is a purely mathematical construct, which governs the rate at which gambler's ruin occurs. Thus, the value of tau can be completely arbitrary.
     
  18. Jul 27, 2016 #17

    haruspex

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member

    But in that case the matrix T must depend on its value, no?
    One approach is to sum the probabilities that should add to 1 then set tau in such a way that they do.
     
  19. Jul 28, 2016 #18
    Agreed.

    The professor suggest that I set the value of tau equal to 1.

    With tau = 1, I get the following column matrix:

    ulP =

    0.8000
    0.6000
    0.4000
    0.2000

    While sum(ulP) = 2.0000.

    Now, none of the probabilites are greater than 1 on their own. Not even when I set the size of the matrix equal to 100.

    What do you think each row represents?
     
  20. Jul 28, 2016 #19

    haruspex

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member

    I don't think the sum of these is interesting. It's hard to know what they mean.
     
  21. Jul 28, 2016 #20
    I'm not even sure what significance the column vector for the ultimate probability has.
     
  22. Jul 28, 2016 #21

    Ray Vickson

    User Avatar
    Science Advisor
    Homework Helper

    Isn't it explained in the attachment?

    You have a "ruin" probability R(i) for each starting state i = 1,2, .., M-1. So, you ought to have a vector of ruin probabilities, whose components are R(i) for i = 1,1, ..., M-1. Of course, for each i we must have P(ruin)+P(not ruined) = 1, but there is no reason at all that the R(i) themselves should have any particular sum, such as 1.
     
  23. Jul 28, 2016 #22
    But I just messaged the professor that I get 1.2 along the diagonal and 0.8 at the end points in a 4x4 matrix, but since probability can't be greater than 1, then I do not think it is correct. That is for the matrix that ulP produces.
     
  24. Jul 28, 2016 #23

    haruspex

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member

    The intended meaning is that each represents the probability of eventual ruin given a certain initial cash level. But since we do not know how to set tau, they are actually some fixed multiple of that. The ratios between them will be meaningful, but not the exact values.
    I assume T is a transition matrix. If you were to flip it and run the same analysis you should get the probabilities of ending up at the other absorbing barrier. In this way, you could find, for a given starting point, the two probabilities for the eventual state. If these do not add up to 1, adjust tau accordingly.
     
  25. Jul 28, 2016 #24

    Ray Vickson

    User Avatar
    Science Advisor
    Homework Helper

    Could you please show an actual example of the 4x4 matrix T you get? And, could you please state exactly is the numerical value of the constant "c" in the differential equation dn(t) = c*T*n(t) that you have solved? Can you tell us exactly what formula you use to get u(i)? Please give actual mathematical expressions, not just Matlab code; not all of us here have access to Matlab or are even very familiar with its syntax.

    Give the actual numerical values for the matrix T, and please do NOT attach a file---just type it out here. One easy way to type out a matrix T is to write T = [Row1, Row2, Row3, Row4], where Row_i = [a,b,c,d] . For example, we could write [[1,2,3],[4,5,6],[7,8,9]] for the matrix
    $$ \pmatrix{1&2&3\\4&5&6\\7&8&9} $$
     
  26. Jul 29, 2016 #25
    I talked to the professor again today. We're only interested in the first row of the inverse matrix T; it gives us the ultimate probability of ruin. By multiplying the first row with n0 - a column vector of all zeros, except in one place, which has a one.

    Now, the professor also talked about multiplying the inverse matrix of T by an identiy matrix, which should return what we're interested in.


    Now,
    [tex] T = \begin{pmatrix}
    -2 & 1 & 0 & 0 \\
    1 & -2 & 1 & 0 \\
    0 & 1 & -2 & 1 \\
    0 & 0 & 1 & -2 \\
    \end{pmatrix}
    [/tex]

    and
    [tex] T^{-1} = \begin{pmatrix}
    -0.8 & -0.6 & -0.4 & -0.2 \\
    -0.6 & -1.2 & -0.8 & -0.4 \\
    -0.4 & -0.8 & -1.2 & -0.6 \\
    -0.2 & -0.4 & -0.6 & -0.8 \\
    \end{pmatrix}
    [/tex]

    while (matlab notation - hence the odd -0)
    [tex] \textbf{I} = T^{-1}*T = \begin{pmatrix}
    1 & 0 & 0 & 0 \\
    -0 & 1 & 0 & -0 \\
    0 & 0 & 1 & 0 \\
    0 & 0 & 0 & 1 \\
    \end{pmatrix}
    [/tex]
     
    Last edited: Jul 29, 2016
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted