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`;

[Maple Math]

> L := array(1..20);

[Maple Math]

> P := matrix(3,3,[.8,.1,.1,.3,.2,.5,.2,.3,.5]);

[Maple Math]

> L[1] := matrix(3,3,[.8,.1,.1,.3,.2,.5,.2,.3,.5]);

[Maple Math]

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]));

[Maple Math]

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]);

[Maple Math]

> print(3,TX,evalm(L[3]));

[Maple Math]

> print(6,TX,evalm(L[6]));

[Maple Math]

> print(20,TX,evalm(L[20]));

[Maple Math]



The Gambler's Ruin Problem.

> restart;

> with(linalg):

Warning, new definition for norm

Warning, new definition for trace

> TX := `Step Transition Matrix`;

[Maple Math]

> L := array(1..100);

[Maple Math]

> 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]);

[Maple Math]

> 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]);

[Maple Math]

> for i from 2 to 100 do

> L[i] := P&*L[i-1];

> od:

> print(1,TX,evalm(L[1]));

[Maple Math]

> print(3,TX,evalm(L[3]));

[Maple Math]

> print(6,TX,evalm(L[6]));

[Maple Math]

> print(20,TX,evalm(L[20]));

[Maple Math]

> print(50,TX,evalm(L[50]));

[Maple Math]
[Maple Math]

> print(100,TX,evalm(L[100]));

[Maple Math]
[Maple Math]

> ?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);

[Maple Math]

> print(P);

[Maple Math]

> Q := submatrix(P,3..5,3..5);

[Maple Math]

The identity matrix is Id in Maple. I is used for the imaginary unit in complex numbers.

> Id := array(identity,1..3,1..3);

[Maple Math]

> print(Id);

[Maple Math]

> N := inverse(Id-Q);

[Maple Math]

> T := evalm(col(N,1)+col(N,2)+col(N,3));

[Maple Math]