Debian Codegraph @

contrib/ms-sbvar/TZcode/MatlabFiles/fn_ergodp.m

raw
1 function gpi = fn_ergodp(P)
2 % gpi = fn_ergodp(P)
3 % Compute the ergodic probabilities. See Hamilton p.681.
4 %
5 % P: n-by-n matrix of transition matrix where all elements in each column sum up to 1.
6 %-----
7 % gpi: n-by-1 vector of ergodic probabilities.
8 %
9 % Tao Zha August 2000
10 %
11 % Copyright (C) 1997-2012 Tao Zha
12 %
13 % This free software: you can redistribute it and/or modify
14 % it under the terms of the GNU General Public License as published by
15 % the Free Software Foundation, either version 3 of the License, or
16 % (at your option) any later version.
17 %
18 % It is distributed in the hope that it will be useful,
19 % but WITHOUT ANY WARRANTY; without even the implied warranty of
20 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 % GNU General Public License for more details.
22 %
23 % If you did not received a copy of the GNU General Public License
24 % with this software, see <http://www.gnu.org/licenses/>.
25 %
26
27
28 [gpim,gpid] = eig(P); % m: matrix; d: diagonal
29 [gpidv,gpidvinx] = sort(diag(gpid));
30 gpidv = fliplr(gpidv);
31 gpidvinx = flipud(gpidvinx);
32 gpim = gpim(:,gpidvinx);
33 gpi = gpim(:,1)/sum(gpim(:,1));