-
Notifications
You must be signed in to change notification settings - Fork 1
/
aim_eig.m
98 lines (76 loc) · 2.68 KB
/
aim_eig.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
function [b,rts,ia,nexact,nnumeric,lgroots,mcode] = aim_eig(h,neq,nlag,nlead,condn,uprbnd)
%
% [b,rts,ia,nexact,nnumeric,lgroots,mcode] = ...
% aim_eig(h,neq,nlag,nlead,condn,uprbnd)
%
% Solve a linear perfect foresight model using the matlab eig
% function to find the invariant subspace associated with the big
% roots. This procedure will fail if the companion matrix is
% defective and does not have a linearly independent set of
% eigenvectors associated with the big roots.
%
% Input arguments:
%
% h Structural coefficient matrix (neq,neq*(nlag+1+nlead)).
% neq Number of equations.
% nlag Number of lags.
% nlead Number of leads.
% condn Zero tolerance used as a condition number test
% by numeric_shift and reduced_form.
% uprbnd Inclusive upper bound for the modulus of roots
% allowed in the reduced form.
%
% Output arguments:
%
% b Reduced form coefficient matrix (neq,neq*nlag).
% rts Roots returned by eig.
% ia Dimension of companion matrix (number of non-trivial
% elements in rts).
% nexact Number of exact shiftrights.
% nnumeric Number of numeric shiftrights.
% lgroots Number of roots greater in modulus than uprbnd.
% mcode Return code: see function aimerr.
%
if(nlag<1 || nlead<1)
error('Aim_eig: model must have at least one lag and one lead.');
end
% Initialization.
nexact = 0;
nnumeric = 0;
lgroots = 0;
iq = 0;
mcode = 0;
qrows = neq*nlead;
qcols = neq*(nlag+nlead);
bcols = neq*nlag;
q = zeros(qrows,qcols);
rts = zeros(qcols,1);
% Compute the auxiliary initial conditions and store them in q.
[h,q,iq,nexact] = ex_shift(h,q,iq,qrows,qcols,neq);
if (iq>qrows)
mcode = 61;
return;
end
[h,q,iq,nnumeric] = numshift(h,q,iq,qrows,qcols,neq,condn);
if (iq>qrows)
mcode = 62;
return;
end
% Build the companion matrix. Compute the stability conditions, and combine them with the auxiliary initial conditions in q.
[a,ia,js] = build_a(h,qcols,neq);
if (ia ~= 0)
[w,rts,lgroots] = eigsys(a,uprbnd);
q = copy_w(q,w,js,iq,qrows);
end
test = nexact+nnumeric+lgroots;
if (test > qrows) mcode = 3;
elseif (test < qrows) mcode = 4;
end
% If the right-hand block of q is invertible, compute the reduced form.
[nonsing,b] = reduform(q,qrows,qcols,bcols,neq,condn);
if ( nonsing & mcode==0) mcode = 1;
elseif (~nonsing & mcode==0) mcode = 5;
elseif (~nonsing & mcode==3) mcode = 35;
elseif (~nonsing & mcode==4) mcode = 45;
end
return