function pi = ergodic(P);
%ERGODIC    compute the stationary probabilities for the Markov chain
%           with transition function P, that is
%
%                  pi = P' * pi,    sum_i pi(i) = 1.
%
%           Ellen McGrattan, 5-29-00
%

Pt  = P';
n   = length(P);
pi  = (eye(n-1)-Pt(1:n-1,1:n-1)+Pt(1:n-1,n)*ones(1,n-1))\Pt(1:n-1,n);
pi  = [pi;1-sum(pi)];

