Monopoly Maple Tips:

As always, don't forget the all important

\with(linalg);

OK gang. What follows is a Maple version of the Monopoly lecture I gave Monday. We did this by hand, but this way you can see the code involved to do the problem in your project assignment. This is followed by some pointers on how to handle the big 40 x 40 Monopoly problem.

*****************************
We first consider the 3 space Monopoly board consisting of Go (space 1), Jail (space 2) and Free Parking (space 3). Using our standard two sided die, the transition matrix looks like:

\R:=matrix([ [0,1/2,1/2], [1/2,0,1/2], [1/2,1/2,0] ]);

Let's assume we start the game on Go:

\x0:=vector([1,0,0]);

To see what the probabilities look like after one roll we compute

\ x1:=multiply(R,x0);

To see what things look like after 4 rolls we just get

\ x4:=multiply(R^4,x0);

***Quick note about computations in Maple. If you enter your matrices and vectors as fractions, the computations should all be in fractions. If just one of the entries has a decimal (put in a 1.0 instead of 1) everthing will switch to decimals. If you use decimals, the command

\ Digits:=3;

should keep things to a reasonable size. My advice is to use decimals when you are estimating long-run distributions with high powers of the transition matrix, but use fractions when you are solving directly for the eigenvectors in the nullspace of R-I.***

OK--back to our Monopoly board.. The argument was that things seem to be evening out, and that after a long while we should get closer and closer to the "long run" distribution

\ u:=([1/3,1/3,1/3]);

If we apply the matrix R to this vector u,

\ mutilply(R,u);

we get Ru=u, meaning that u is a fixed vector. Said another way, u is an eigenvector with eigenvalue 1. With Maple around, we can actually see all of the eigenvalues just by asking:


\ eigenvalues(R);

Now for a little twist. In class, we changed the free parking square into the Policeman. We are going to do this again here, but in a slightly different way. Rather than change the matrix R, let's leave it alone, and invent a new matrix J (for Jail) that sends anybody on the policeman's square to Jail and leaves all other squares unaffected. This matrix looks very much like the identity except that we are going to move the 1 in column 3 (the policeman's column) to the second row (the Jail row). Here's how to do it for our 3x3 game in class:


\ J:=matrix([ [1, 0, 0], [0, 1, 1], [0,0,0] ]);
\ evalm(J);

By taking the product, we can get the combined effect of first rolling the die (multiply by R) and then checking to see if we happen to be on the Policeman's space, in which case we send ourselves to Jail (multiply by J).


\ M:=J.R;
\ evalm(M);

Just to clear up any confusion, notice that in class we threw away the third row and column since the policeman's square can really never be occupied (note the row of zeros across the bottom). Leaving it in will not cause any confusion hopefully, and might even prevent some as you work on the 4x4 problem.

OK, what do we do with this matrix? There are two possibilities. You can use Maple to hit our starting vector with bigger and bigger powers of M if you like.

\ multiply(M^5,x0);

\ multiply(M^10,x0);

But let's find the long run probabilities the more elegant way. What we have learned is that the long run distribitution will be an eigenvector with eigenvalue 1. Let's make sure we have an eigenvalue of 1:


\ eigenvalues(M);

Excellent. Now, we need to find the eigenvector that goes with it. To do this, we need to look in the nullspace of M-I:


\ Id:=diag(1,1,1);

\ gaussjord(M-Id);

What you should see is a reduced matrix with one free variable. The pivot in column 3 means that x3=0 (that's the policeman's square) and the vector x_infinity = (1,2,0) is in the nullspace. Of course, (1,2,0) does not make sense as a long-run distribution because the entries in this matrix don't add up to 1. This is easy to fix – all we have to do is scale our vector by 1/3. The result is still an eigenvector that goes with eigenvalue 1 (remember that eigenvectors really just specify a direction and so any scaled version of that vector is as good as any other), and this time we do get a proper probability distribution: (1/3, 2/3, 0). In the long run, players in this silly game spend 2/3rds of their time in JAIL, and 1/3 rd of their time on GO, waiting to be incarcerated.

Here is how to carry out this scaling process using Maple:

Having arrived at the proper transition matrix M, first have a look at the nullspace of M-Id

\ nullspace(M-Id);

Maple will return a basis for this space. If your matrix M is correct, this basis should have exactly one vector in it. In order to get your electronic hands on an actual vector from the nullspace, set

\ v:=nullspace(M-Id)[1];

As an fyi, the [1] is asking for the first vector from this basis. Because there is only one vector in the basis this step looks a little silly – but you need to do it because nullspace(M-Id) is a set while v is an actual vector.

Your next job is to scale the vector v to be a proper probability distribution. Step one is to add up all the entries:

\ s:=sum(v[n], n=1..3);

Note that s is a real number. The vector we want is:

\ x_infinity:=(1/s)*v;

The * in the previous step is the shift of the “8” which gives scalar multiplication. (That was true in older versions of Maple--I think that the newest version is more flexible about this.) If Maple does not show you this vector on its own, you can always request a viewing:

\ evalm(x_infinity);

To return to the question of whether decimals or fractions are the better way to proceed, my strong vote would be to do everything in fractions-- this should prevent you from having any computational rounding errors, which I suspect will be an issue when you are working with a 40x40 matrix. On the other hand, the numbers will be so big that they will be unreadable – so at the end you will want to turn everything into modest sized decimals. Again, to do that all you need to do is introduce one calculation that uses a decimal point:

>evalm(1.0*x_infinity);

If you have not already, make sure you limit the display to just a few digits:

>Digits:=3;

***

A few last words on how to handle the large 40 x 40 case:

First, I will send you all a copy of the rolling matrix.

To create the Jail, Community Chest, and Chance card matrices, use the template button on the left column. When you are selecting this, under “type” you can choose the identity. It should then be a relatively simple matter to go make the needed edits to get the matrix you want.

To create an initial x0 vector, you can also use the matrix template button, and just create a matrix that is 40 x 1.

Finally, be a little careful about what you ask Maple to do. Row reduction is easy computationally speaking, but computing eigenvalues or inverses is computationally harder. You might make the computer blow a few fuses, but this should not prevent you from experimenting and exploring-- just remember to save early and often.

Good luck – and stay in touch with questions, comments, and suggestions for improvement that you discover on your own.