% This m-file calculates the mean first passage time 
% for a Markov Chain - to use specify state i and j 
% the one step transition matrix P and N the size of P
% the answer is placed in ETij   
pi0 =  zeros(1:N);
pi0(i) = 1; 
if i ~= j
 for r = 1:N
   for c = 1:N
     if r ~= j
         if c ~= j
           if r < j
             m = r;
           else
             m = r-1;
           end
           if c < j
             k = c;
           else
             k = c-1;
           end  
           R(m,k) = P(r,c);
           pij0(1,k) = pi0(1,c);
         end
     end
   end
 end  
 N1 = N-1;
 A = eye(N1)-R;
 e = ones(N1,1);
 AI = inv(A);
 ETij = pij0*AI*e
else
% for i=j ET_ij is the mean recurrence time = 1/sspi_j
  mcss;
  ETij = 1/sspi(j)  
end
