| 1 |
function zstar = zroot(B) |
| 2 |
% zroot(B); find roots of a matrix polynomial |
| 3 |
% B: the 3 dimensional array B, e.g. B(:,:,1) is B_1, B(:,:,2) is B_2 and |
| 4 |
% B(:,:,p) is B_p. Note: rows correpond to equations. See Judge (1), pp. 763-764. |
| 5 |
% For the system of equations: |
| 6 |
% y_t = B_1*y_{t-1} + ... + B_p*Y_{t-p} + u_t. |
| 7 |
% The corresponding matrix polynomial is: |
| 8 |
% det(eye(m)-B_1*z-...-B_p*z^p) = 0 |
| 9 |
% zroot(B) solves for the roots of this above polynomial. The matrices B_1, B_2,....B_p |
| 10 |
% are passed through B. The degree of the matrix polynomial is determined |
| 11 |
% by the size of the third dimension of B. |
| 12 |
% Each of the B(:,:,i) must be an m by m matrix. |
| 13 |
|
| 14 |
% ZROOT was written by Clark A. Burdick of the research |
| 15 |
% department of the Federal Reserve Bank of Atlanta. |
| 16 |
% Original: July 31, 1997 |
| 17 |
% Last Modified: July 31, 1997 |
| 18 |
|
| 19 |
% TO BE DONE: |
| 20 |
% Better bullet proofing |
| 21 |
% |
| 22 |
% Copyright (C) 1997-2012 Tao Zha |
| 23 |
% |
| 24 |
% This free software: you can redistribute it and/or modify |
| 25 |
% it under the terms of the GNU General Public License as published by |
| 26 |
% the Free Software Foundation, either version 3 of the License, or |
| 27 |
% (at your option) any later version. |
| 28 |
% |
| 29 |
% It is distributed in the hope that it will be useful, |
| 30 |
% but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 31 |
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 32 |
% GNU General Public License for more details. |
| 33 |
% |
| 34 |
% If you did not received a copy of the GNU General Public License |
| 35 |
% with this software, see <http://www.gnu.org/licenses/>. |
| 36 |
% |
| 37 |
|
| 38 |
|
| 39 |
[a b c] = size(B); |
| 40 |
syms z; |
| 41 |
thepoly = eye(size(B(:,:,1)))-B(:,:,1)*z; |
| 42 |
for i=2:c |
| 43 |
thepoly = thepoly-B(:,:,i)*z^i; |
| 44 |
end |
| 45 |
zstar=roots(sym2poly(det(thepoly))); |
| 46 |
|