Adds an option ('incidence') to model_info in order to print out the gross and the reordered incidence matrices
parent
e51d8f7a56
commit
151922e96e
|
@ -1,4 +1,4 @@
|
|||
function model_info;
|
||||
function model_info(varargin);
|
||||
%function model_info;
|
||||
|
||||
% Copyright (C) 2008-2010 Dynare Team
|
||||
|
@ -66,12 +66,115 @@ if(isfield(M_,'block_structure'))
|
|||
end;
|
||||
fprintf('\n\n');
|
||||
end;
|
||||
|
||||
%printing the gross incidence matrix
|
||||
IM_star = [kron(ones(M_.endo_nbr, M_.endo_nbr-1), blanks(3)) blanks(M_.endo_nbr)'];
|
||||
for i = 1:3
|
||||
n = size(M_.block_structure.incidence(i).sparse_IM,1);
|
||||
for j = 1:n
|
||||
if ismember(M_.block_structure.incidence(i).sparse_IM(j,2), M_.state_var)
|
||||
IM_star(M_.block_structure.incidence(i).sparse_IM(j,1), 3 * (M_.block_structure.incidence(i).sparse_IM(j,2) - 1) + 1) = 'X';
|
||||
else
|
||||
IM_star(M_.block_structure.incidence(i).sparse_IM(j,1), 3 * (M_.block_structure.incidence(i).sparse_IM(j,2) - 1) + 1) = '1';
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
seq = 1: M_.endo_nbr;
|
||||
blank = [ blanks(size(M_.endo_names,2)); blanks(size(M_.endo_names,2))];
|
||||
for i = 1:M_.endo_nbr
|
||||
if i == 1
|
||||
var_names = [blank; M_.endo_names(i,:)];
|
||||
else
|
||||
var_names = [var_names; blank; M_.endo_names(i,:)];
|
||||
end;
|
||||
end;
|
||||
if nargin == 1 && strcmp(varargin{1},'incidence')
|
||||
topp = [char(kron(blanks(ceil(log10(M_.endo_nbr))),ones(size(M_.endo_names,2),1))) var_names' ];
|
||||
bott = [int2str(seq') blanks(M_.endo_nbr)' blanks(M_.endo_nbr)' IM_star];
|
||||
fprintf('\n Gross incidence matrix\n');
|
||||
fprintf(' =======================\n');
|
||||
disp([topp; bott]);
|
||||
|
||||
%printing the reordered incidence matrix
|
||||
IM_star_reordered = [kron(ones(M_.endo_nbr, M_.endo_nbr-1), blanks(3)) blanks(M_.endo_nbr)'];
|
||||
eq(M_.block_structure.equation_reordered) = seq;
|
||||
va(M_.block_structure.variable_reordered) = seq;
|
||||
barre_blank = [ barre(size(M_.endo_names,2)); blanks(size(M_.endo_names,2))];
|
||||
cur_block = 1;
|
||||
for i = 1:M_.endo_nbr
|
||||
past_block = cur_block;
|
||||
while ismember(M_.block_structure.variable_reordered(i), M_.block_structure.block(cur_block).variable) == 0;
|
||||
cur_block = cur_block + 1;
|
||||
end;
|
||||
if i == 1
|
||||
var_names = [blank; M_.endo_names(M_.block_structure.variable_reordered(i),:)];
|
||||
else
|
||||
if past_block ~= cur_block
|
||||
var_names = [var_names; barre_blank; M_.endo_names(M_.block_structure.variable_reordered(i),:)];
|
||||
else
|
||||
var_names = [var_names; blank; M_.endo_names(M_.block_structure.variable_reordered(i),:)];
|
||||
end
|
||||
end;
|
||||
end;
|
||||
topp = [char(kron(blanks(ceil(log10(M_.endo_nbr))),ones(size(M_.endo_names,2),1))) var_names' ];
|
||||
n_state_var = length(M_.state_var);
|
||||
IM_state_var = zeros(n_state_var, n_state_var);
|
||||
inv_variable_reordered(M_.block_structure.variable_reordered) = 1:M_.endo_nbr;
|
||||
state_equation = M_.block_structure.equation_reordered(inv_variable_reordered(M_.state_var));
|
||||
for i = 1:3
|
||||
n = size(M_.block_structure.incidence(i).sparse_IM,1);
|
||||
for j = 1:n
|
||||
[tf, loc] = ismember(M_.block_structure.incidence(i).sparse_IM(j,2), M_.state_var);
|
||||
if tf
|
||||
IM_star_reordered(eq(M_.block_structure.incidence(i).sparse_IM(j,1)), 3 * (va(M_.block_structure.incidence(i).sparse_IM(j,2)) - 1) + 1) = 'X';
|
||||
[tfi, loci] = ismember(M_.block_structure.incidence(i).sparse_IM(j,1), state_equation);
|
||||
if tfi
|
||||
IM_state_var(loci, loc) = 1;
|
||||
end;
|
||||
else
|
||||
IM_star_reordered(eq(M_.block_structure.incidence(i).sparse_IM(j,1)), 3 * (va(M_.block_structure.incidence(i).sparse_IM(j,2)) - 1) + 1) = '1';
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
fprintf('1: non nul element, X: non nul element related to a state variable\n');
|
||||
|
||||
cur_block = 1;
|
||||
i_last = 0;
|
||||
block = {};
|
||||
for i = 1:n_state_var;
|
||||
past_block = cur_block;
|
||||
while ismember(M_.state_var(i), M_.block_structure.block(cur_block).variable) == 0;
|
||||
cur_block = cur_block + 1;
|
||||
end;
|
||||
if (past_block ~= cur_block) || (past_block == cur_block && i == n_state_var)
|
||||
block(past_block).IM_state_var(1:(i - 1 - i_last), 1:i - 1) = IM_state_var(i_last+1:i - 1, 1:i - 1);
|
||||
i_last = i - 1;
|
||||
end;
|
||||
end;
|
||||
cur_block = 1;
|
||||
for i = 1:M_.endo_nbr
|
||||
past_block = cur_block;
|
||||
while ismember(M_.block_structure.variable_reordered(i), M_.block_structure.block(cur_block).variable) == 0;
|
||||
cur_block = cur_block + 1;
|
||||
end;
|
||||
if past_block ~= cur_block
|
||||
for j = 1:i-1
|
||||
IM_star_reordered(j, 3 * (i - 1) - 1) = '|';
|
||||
end;
|
||||
end;
|
||||
end
|
||||
|
||||
bott = [int2str(M_.block_structure.equation_reordered') blanks(M_.endo_nbr)' blanks(M_.endo_nbr)' IM_star_reordered];
|
||||
fprintf('\n Reordered incidence matrix\n');
|
||||
fprintf(' ==========================\n');
|
||||
disp([topp; bott]);
|
||||
fprintf('1: non nul element, X: non nul element related to a state variable\n');
|
||||
end;
|
||||
else
|
||||
fprintf('There is no block decomposition of the model.\nUse ''block'' model''s option.\n');
|
||||
end;
|
||||
|
||||
|
||||
function ret=Sym_type(type);
|
||||
function ret=Sym_type(type)
|
||||
UNKNOWN=0;
|
||||
EVALUATE_FORWARD=1;
|
||||
EVALUATE_BACKWARD=2;
|
||||
|
@ -105,5 +208,12 @@ switch (type)
|
|||
end;
|
||||
|
||||
|
||||
function ret = barre(n)
|
||||
s = [];
|
||||
for i=1:n;
|
||||
s = [s '|'];
|
||||
end;
|
||||
ret = s;
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue