Debian Codegraph @

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

raw
1 function [z2,eu2,div]=gensys_z2new(g0,g1,c,psi,gpi)
2 %[z2,eu2,div]=gensys_z2new(g0,g1,c,psi,gpi)
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 n2 = size(gpi,2); %number of expectational errors.
36 realsmall=1e-9;
37 %fixdiv=(nargin==6);
38 n=size(g0,1);
39 [a b q z v]=qz(g0,g1);
40 %if ~fixdiv, div=1.01; end
41 %nunstab=0;
42 zxz=0;
43 for i=1:n
44 % ------------------div calc------------
45 % if ~fixdiv
46 % if abs(a(i,i)) > 0
47 % divhat=abs(b(i,i))/abs(a(i,i));
48 % % bug detected by Vasco Curdia and Daria Finocchiaro, 2/25/2004 A root of
49 % % exactly 1.01 and no root between 1 and 1.02, led to div being stuck at 1.01
50 % % and the 1.01 root being misclassified as stable. Changing < to <= below fixes this.
51 % if 1+realsmall<divhat & divhat<=div
52 % div=.5*(1+divhat);
53 % end
54 % end
55 % end
56 % ----------------------------------------
57 %nunstab=nunstab+(abs(b(i,i))>div*abs(a(i,i)));
58 if abs(a(i,i))<realsmall & abs(b(i,i))<realsmall
59 zxz=1;
60 end
61 end
62
63 gev=[diag(a) diag(b)];
64 gevsort = sort(abs(gev(:,1)).\abs(gev(:,2)));
65 div = (gevsort(end-n2+1) + gevsort(end-n2))/2.0;
66 if ~zxz
67 [a b q z]=qzdiv(div,a,b,q,z);
68 end
69
70
71 if zxz
72 disp('Coincident zeros. Indeterminacy and/or nonexistence.')
73 eu2=[-2;-2];
74 % correction added 7/29/2003. Otherwise the failure to set output
75 % arguments leads to an error message and no output (including eu2).
76 G1=[];C=[];impact=[];fmat=[];fwt=[];ywt=[];gev=[];
77 z2=[];
78 return
79 end
80 %q1=q(1:n-nunstab,:);
81 %q2=q(n-nunstab+1:n,:);
82 %z1=z(:,1:n-nunstab)';
83
84 %if (nunstab>0)
85 % z2=z(:,n-nunstab+1:n);
86 %else
87 % z2=z(:,n-n2+1:n);
88 %end
89
90 z2=z(:,n-n2+1:n);