Now let's return to the difference equation we have above. The solution method
is virtually the same as that in the two examples in the previous section.
First assume a solution form
We have exactly the same quadratic equation that appeared in the second example
in the previous section if . We need the two solutions of
Solve[ p z^2 - z + q ==0, z]which gives the output
1 Sqrt[1 - 4 p q] 1 Sqrt[1 - 4 p q] - + --------------- - - --------------- p p p p Out[1]= {{z -> -------------------}, {z -> -------------------}} 2 2Recall that the values of and are related and that we can get a simpler expression using the two commands
q = 1 - p Solve[ p z^2 - z + q ==0, z]This gives the output
1 Out[4]= {{z -> -1 + -}, {z -> 1}} pNote that we can rewrite the first solution
This means the solution is
sc[a_] := c1 + c2 (q/p)^a q = 1 - p Solve[ { sc[0] == 0, sc[c] == 1 }, {c1,c2}]The first command sets up a function, which is the general solution of the finite difference equation. The second command sets up the relationship between and . The last command sets up the system of equations (in the first set of braces), defines the unknowns to solve for, and and solves the system. This would give you the correct solution for the coefficients. You should take a look at the Mathematica notebook for this chapter which goes through all these commands.
To finish off this section we will do an example where we plug in some numbers.
Clear[p,g] sc[a_,c_,p_] := (p^c/(p^c-(1-p)^c)) (1-((1-p)/p)^a) g = Plot[sc[15,21,p], {p,0.0,1.0}]The two commands will produce a plot, but you will get a few errors from the execution. The problem is that the form forces a division by zero in the second factor. To avoid this, try
Clear[p,expr,g] sc[a_,c_,p_] := (p^c/(p^c-(1-p)^c)) (1-((1-p)/p)^a) expr = Expand[sc[15,21,p]] g = Plot[expr, {p,0.0,1.0}]In this case we will see a graph like the one shown in Figure (1.1). The probability of ending up with $21 starting with $15 is very small for probabilities that are less than 1/2. Around 1/2 the chance of success grows very rapidly and if the probability of winning an individual play of the game is larger than 1/2, the chance of success is close to 1.
It is important to note that this simple problem requires a fairly messy solution process. If the problem becomes any more complicated there is no guarantee that we would be able to get an exact representation of the probability. Another point of interest is that the solution process is basically one that we have seen before in an ordinary differential equations course. So we have determined an exact solution for a problem that is a simplification of the problems we first discussed. In general, we will not be able to find exact solutions to the problems that we are faced with. Even the simple examples in the introduction will not lend themselves to the simple analysis we have done. So, we will introduce the concept of doing a simulation of the process. In cases where we cannot determine an exact solution we may be able to get accurate approximate results using a simulation.