-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild_a.m
45 lines (33 loc) · 1 KB
/
build_a.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
function [a,ia,js] = build_a(h,qcols,neq)
%
% [a,ia,js] = build_a(h,qcols,neq)
%
% Build the companion matrix, deleting inessential lags.
%
% Solve for x_{t+nlead} in terms of x_{t+nlag},...,x_{t+nlead-1}.
%
qcols;
neqi=neq;
left = 1:qcols;
right = qcols+1:qcols+neq;
h(:,left) = -h(:,right)\h(:,left);
% Build the big transition matrix.
a = zeros(qcols,qcols);
if(qcols > neq)
eyerows = 1:qcols-neq;
eyecols = neq+1:qcols;
a(eyerows,eyecols) = eye(qcols-neq);
end
hrows = qcols-neq+1:qcols;
a(hrows,:) = h(:,left);
% Delete inessential lags and build index array js. js indexes the columns in the big transition matrix that correspond to the essential lags in the model. They are the columns of q that will get the unstable left eigenvectors.
js = 1:qcols;
zerocols = sum(abs(a)) == 0;
while( any(zerocols) )
a(:,zerocols) = [];
a(zerocols,:) = [];
js(zerocols) = [];
zerocols = sum(abs(a)) == 0;
end
ia = length(js);
return