Home > sp > chutes.m

chutes

PURPOSE ^

chutes.m sets up and displays various matrices relating to Chutes and Ladders

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

 chutes.m sets up and displays various matrices relating to Chutes and Ladders

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % chutes.m sets up and displays various matrices relating to Chutes and Ladders
0002 
0003 A=zeros(102,102);     % blank matrix to work with
0004                       % state 102 is fictitious, to help with pcolor below
0005 
0006 for i=1:100,      
0007   for j=(i+1):(i+6),  % as if just rolling the die, no chutes or ladders
0008     if j>100 
0009        k=i;           % stay where you are; exact spin to get to 100
0010     else
0011        k=j;
0012     end
0013     A(i,k)=A(i,k)+1/6;
0014   end
0015 end    
0016 
0017 for j=1:6,           % state 101 is where you are before the game starts
0018   A(101,j)=1/6;
0019 end
0020 
0021 CL=eye(102,102);     % the transition matrix for chutes and ladders
0022 
0023 B=1:102;    % a vector to tell where the chutes and ladders go
0024 B(1)  = 38;
0025 B(4)  = 14;
0026 B(9)  = 31;
0027 B(28) = 84;
0028 B(21) = 42;
0029 B(28) = 84;
0030 B(36) = 44;
0031 B(51) = 67;
0032 B(71) = 91;
0033 B(80) = 100;
0034 B(98) = 78;
0035 B(95) = 75;
0036 B(93) = 73;
0037 B(87) = 24;
0038 B(64) = 60;
0039 B(62) = 19;
0040 B(56) = 53;
0041 B(49) = 11;
0042 B(47) = 26;
0043 B(16) = 6;
0044 
0045 I = eye(102);
0046 CL = I(B,:);
0047 
0048 P=A*CL;              % the transition matrix
0049 P=CL*A;
0050 
0051 %colormap(1-gray);
0052 
0053 subplot(2,2,1);
0054 pcolor(A);
0055 axis ij;
0056 shading flat;
0057 title('The spin matrix A');
0058 
0059 subplot(2,2,2);
0060 pcolor(CL);
0061 axis ij;
0062 shading flat;
0063 title('The chutes and ladders matrix CL');
0064 
0065 subplot(2,2,3);
0066 pcolor(P);
0067 axis ij;
0068 shading flat;
0069 title('The transition matrix P');
0070 
0071 t=[1:99, 101];       % index vector of transient states, to pull out Q
0072 Q=P(t,t);            % Pulls out columns and rows 1 to 99 of P
0073 S=inv(eye(100)-Q);   % matrix telling expected number of visits
0074 R=zeros(102,102);    % set up a blank potential matrix
0075 R(t,t)=S;            % the potential matrix, with 0 replacing infinity
0076 
0077 subplot(2,2,4);
0078 pcolor(R);          % Plot the matrix S as a grayscale image
0079 shading flat;
0080 title('Expected number of visits R');
0081 axis ij;
0082 
0083 r=[100];             % index vector of recurrent states, to pull out L
0084 L=P(t,r);            % Pulls out rows t and columns r of P
0085 G=S*L;               % Matrix of absorption probabilities
0086 
0087 break
0088 
0089 i=(0:0.01:1)';       % For fixing the gray-scaling
0090 mymap = (i.^(1/3))*[1 1 1];
0091 colormap(1-mymap);   % this changes the gray-scale levels in a useful way
0092

Generated on Mon 17-Mar-2008 10:33:42 by m2html © 2003