Solving the Toothpaste and Gambler's Ruin Problems
> restart;
> with(linalg):
Warning, new definition for norm
Warning, new definition for trace
The Toothpaste Problem
> TX := `Step Transition Matrix`;
> L := array(1..20);
> P := matrix(3,3,[.8,.1,.1,.3,.2,.5,.2,.3,.5]);
> L[1] := matrix(3,3,[.8,.1,.1,.3,.2,.5,.2,.3,.5]);
For matrices A and B the product AB must be written A&*B in Maple.
> for i from 2 to 20 do
> L[i]:=P&*L[i-1];
> od:
> print(1,TX,evalm(L[1]));
evalm Evaluate the matrix. Sometimes, but not always, Maple will write the matrix symbolically rather than evaluating its entries. If this happens, use evalm . Note the difference in the statements below.
> print(3,TX,L[3]);
> print(3,TX,evalm(L[3]));
> print(6,TX,evalm(L[6]));
> print(20,TX,evalm(L[20]));
The Gambler's Ruin Problem.
> restart;
> with(linalg):
Warning, new definition for norm
Warning, new definition for trace
> TX := `Step Transition Matrix`;
> L := array(1..100);
> P := matrix(5,5,[1,0,0,0,0,0,1,0,0,0,.5,0,0,.5,0,0,0,.5,0,.5,0,.5,0,.5,0]);
> L[1]:=matrix(5,5,[1,0,0,0,0,0,1,0,0,0,.5,0,0,.5,0,0,0,.5,0,.5,0,.5,0,.5,0]);
> for i from 2 to 100 do
> L[i] := P&*L[i-1];
> od:
> print(1,TX,evalm(L[1]));
> print(3,TX,evalm(L[3]));
> print(6,TX,evalm(L[6]));
> print(20,TX,evalm(L[20]));
> print(50,TX,evalm(L[50]));
> print(100,TX,evalm(L[100]));
> ?submatrix;
The command above will give information on the submatrix command. The Maple help directory is very large and anything you want to know can be accessed using the question mark as in the command above. ( WHY HAVE I FAILED TO POINT THIS OUT UNTIL NOW? (I am asking myself.) ).
> B := submatrix(L[100],3..5,1..2);
> print(P);
> Q := submatrix(P,3..5,3..5);
The identity matrix is Id in Maple. I is used for the imaginary unit in complex numbers.
> Id := array(identity,1..3,1..3);
> print(Id);
> N := inverse(Id-Q);
> T := evalm(col(N,1)+col(N,2)+col(N,3));