Home > sp > gambler_visits.m

gambler_visits

PURPOSE ^

gambler_visits.m displays the expected number of visits to transient states matrix S and the probability of hitting matrix F

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

 gambler_visits.m  displays the expected number of visits to transient states matrix S and the probability of hitting matrix F

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % gambler_visits.m  displays the expected number of visits to transient states matrix S and the probability of hitting matrix F
0002 
0003 N=30;          % total wealth at the table
0004 p=0.5;         % probability of increasing wealth by 1
0005 q=1-p;
0006 
0007 P=zeros(N+1);  % set up transition matrix
0008                % rows 1..(N+1) correspond to wealths 0..N
0009 for i=2:N,
0010    P(i,i-1)=q;
0011    P(i,i+1)=p;
0012 end
0013 P(1,1)=1;      % stay at 0 wealth
0014 P(N+1,N+1)=1;    % stay at wealth N
0015 
0016 mu=zeros(1,N+1);  % set up initial distribution
0017 mu(10)=1;         % start with wealth 10
0018 
0019 Q=P(2:N,2:N);   % pull out the matrix corresponding to transient states
0020 
0021 S=inv(eye(size(Q))-Q);
0022 
0023 x=0.5:1:(N-0.5);
0024 y=x;
0025 
0026 clf;
0027 
0028 subplot(2,1,1);
0029 
0030 pcolor(x, y, [[S zeros(N-1,1)]' zeros(N,1)]');
0031 axis ij;
0032 title('Graphical representation of expected number of visits matrix S');
0033 ylabel('Initial state');
0034 xlabel('Visited state');
0035 
0036 % showmatrix(S);
0037 
0038 F = (S-eye(size(S))) * inv(diag(diag(S)));
0039 
0040 B = [P(2:N,1) P(2:N,N+1)];   % from transient to absorbing states
0041 G = S*B;
0042 
0043 F = [G(:,1) F G(:,2)];       % paste the columns of G before and after F
0044 
0045 F = [[1 zeros(1,N)]; F; [zeros(1,N) 1]];  % add simple rows at the top and
0046                                           % bottom of F
0047 
0048 % showmatrix(F);
0049 
0050 
0051 x=-0.5:1:(N+0.5);
0052 y=x;
0053 
0054 subplot(2,1,2);
0055 
0056 pcolor(x, y, [[F zeros(N+1,1)]' zeros(N+2,1)]');
0057 axis ij;
0058 title('Graphical representation of probability of hitting matrix F');
0059 ylabel('Initial state');
0060 xlabel('Hit state');
0061

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