0001
0002
0003 N=30;
0004 p=0.5;
0005 q=1-p;
0006
0007 P=zeros(N+1);
0008
0009 for i=2:N,
0010 P(i,i-1)=q;
0011 P(i,i+1)=p;
0012 end
0013 P(1,1)=1;
0014 P(N+1,N+1)=1;
0015
0016 mu=zeros(1,N+1);
0017 mu(10)=1;
0018
0019 Q=P(2:N,2:N);
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
0037
0038 F = (S-eye(size(S))) * inv(diag(diag(S)));
0039
0040 B = [P(2:N,1) P(2:N,N+1)];
0041 G = S*B;
0042
0043 F = [G(:,1) F G(:,2)];
0044
0045 F = [[1 zeros(1,N)]; F; [zeros(1,N) 1]];
0046
0047
0048
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