
/* inputs a continuous-time Markov rate matrix q; elements (i,i) are the
   negatives of the rates out of state i, while for j not i the 
   elements (j,i) are the rates from j into i; returns the steady-
   state probabilities vector pi
   
   the basic idea is

   PI * Q = 0
   also PI * 1V = 1  (1V is a vector of all 1s)
   then PI * QM = (0,0,...,0,1) 
      where QM is Q but modified so that the last column is
      all 1s 
*/

Function("solvedmc",{q})  [
   nrows:=Length(q); 
   ForEach(i,1 .. nrows) [q[i][nrows]:=1;]; 
   v:=0*(1 .. nrows); 
   v[nrows]:=1; 
   SolveMatrix(Transpose(q),v); ];

