Debian Codegraph @

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

raw
1 function [z2,eu2]=gensys_z2(g0,g1,c,psi,gpi,div)
2 %[z2,eu2]=gensys_z2(g0,g1,c,psi,gpi,div)
3 %
4 % z2: n-by-k in general where k is the dimension of gpi or the number of expectational errors.
5 % System given as
6 % g0*y(t)=g1*y(t-1)+c+psi*z(t)+gpi*eta(t),
7 % with z an exogenous variable process and eta being endogenously determined
8 % one-step-ahead expectational errors.
9 % Space spanned by z2 is such that z2'*y_t = 0.
10 % If div is omitted from argument list, a div>1 is calculated.
11 %
12 % eu2 = [0, 0] if the rows in Z2 corresponding to the fixed points are zeros (which happens only in the greater-than-2 regime case).
13 % This value is set outside this function.
14 % eu2 = [-2,-2] for coincident zeros.
15 % By Christopher A. Sims
16 % Corrected 10/28/96 by CAS
17 %
18 % Copyright (C) 1997-2012 Christopher A. Sims
19 %
20 % This free software: you can redistribute it and/or modify
21 % it under the terms of the GNU General Public License as published by
22 % the Free Software Foundation, either version 3 of the License, or
23 % (at your option) any later version.
24 %
25 % It is distributed in the hope that it will be useful,
26 % but WITHOUT ANY WARRANTY; without even the implied warranty of
27 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 % GNU General Public License for more details.
29 %
30 % If you did not received a copy of the GNU General Public License
31 % with this software, see <http://www.gnu.org/licenses/>.
32 %
33
34 eu2=NaN*ones(2,1);
35 realsmall=1e-6;
36 fixdiv=(nargin==6);
37 n=size(g0,1);
38 [a b q z v]=qz(g0,g1);
39 if ~fixdiv, div=1.01; end
40 nunstab=0;
41 zxz=0;
42 for i=1:n
43 % ------------------div calc------------
44 if ~fixdiv
45 if abs(a(i,i)) > 0
46 divhat=abs(b(i,i))/abs(a(i,i));
47 % bug detected by Vasco Curdia and Daria Finocchiaro, 2/25/2004 A root of
48 % exactly 1.01 and no root between 1 and 1.02, led to div being stuck at 1.01
49 % and the 1.01 root being misclassified as stable. Changing < to <= below fixes this.
50 if 1+realsmall<divhat & divhat<=div
51 div=.5*(1+divhat);
52 end
53 end
54 end
55 % ----------------------------------------
56 nunstab=nunstab+(abs(b(i,i))>div*abs(a(i,i)));
57 if abs(a(i,i))<realsmall & abs(b(i,i))<realsmall
58 zxz=1;
59 end
60 end
61
62 if ~zxz
63 [a b q z]=qzdiv(div,a,b,q,z);
64 end
65 %gev=[diag(a) diag(b)];
66 if zxz
67 disp('Coincident zeros. Indeterminacy and/or nonexistence.')
68 eu2=[-2;-2];
69 % correction added 7/29/2003. Otherwise the failure to set output
70 % arguments leads to an error message and no output (including eu2).
71 G1=[];C=[];impact=[];fmat=[];fwt=[];ywt=[];gev=[];
72 z2=[];
73 return
74 end
75 %q1=q(1:n-nunstab,:);
76 %q2=q(n-nunstab+1:n,:);
77 %z1=z(:,1:n-nunstab)';
78
79 %if (nunstab>0)
80 % z2=z(:,n-nunstab+1:n);
81 %else
82 % z2=z(:,n-rank(gpi)+1:n);
83 %end
84
85 z2=z(:,n-rank(gpi)+1:n);