From 8cb51e26e670ad604b9e1a1093d4672b55b5bd4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Thu, 25 Oct 2018 15:01:53 +0200 Subject: [PATCH] options_.instruments is now a cell array This fixes crashes under Octave (while MATLAB seems to accept array-indexing with cell arrays). --- matlab/default_option_values.m | 2 +- matlab/discretionary_policy_1.m | 2 +- matlab/dyn_ramsey_static.m | 4 ++-- matlab/evaluate_steady_state.m | 12 ++++++------ 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/matlab/default_option_values.m b/matlab/default_option_values.m index d1a46cb32..0c115e4fe 100644 --- a/matlab/default_option_values.m +++ b/matlab/default_option_values.m @@ -336,7 +336,7 @@ options_.conditional_variance_decomposition = []; % Ramsey policy options_.ramsey_policy = 0; -options_.instruments = []; +options_.instruments = {}; options_.timeless = 0; options_.ramsey.maxit = 500; diff --git a/matlab/discretionary_policy_1.m b/matlab/discretionary_policy_1.m index a88e2bbaa..f154912d4 100644 --- a/matlab/discretionary_policy_1.m +++ b/matlab/discretionary_policy_1.m @@ -115,7 +115,7 @@ end instr_id=nan(instr_nbr,1); for j=1:instr_nbr - vj=deblank(Instruments(j,:)); + vj=deblank(Instruments{j}); vj_id=strmatch(vj, endo_names, 'exact'); if ~isempty(vj_id) instr_id(j)=vj_id; diff --git a/matlab/dyn_ramsey_static.m b/matlab/dyn_ramsey_static.m index c1ef18e05..cf171e847 100644 --- a/matlab/dyn_ramsey_static.m +++ b/matlab/dyn_ramsey_static.m @@ -50,7 +50,7 @@ elseif options_.steadystate_flag k_inst = []; inst_nbr = size(options_.instruments,1); for i = 1:inst_nbr - k_inst = [k_inst; strmatch(options_.instruments(i,:), M.endo_names, 'exact')]; + k_inst = [k_inst; strmatch(options_.instruments{i}, M.endo_names, 'exact')]; end if inst_nbr == 1 %solve for instrument, using univariate solver, starting at initial value for instrument @@ -112,7 +112,7 @@ if options_.steadystate_flag k_inst = []; instruments = options_.instruments; for i = 1:size(instruments,1) - k_inst = [k_inst; strmatch(instruments(i,:), endo_names, 'exact')]; + k_inst = [k_inst; strmatch(instruments{i}, endo_names, 'exact')]; end ys_init=zeros(size(oo.steady_state)); %create starting vector for steady state computation as only instrument value is handed over ys_init(k_inst) = x; %set instrument, the only value required for steady state computation, to current value diff --git a/matlab/evaluate_steady_state.m b/matlab/evaluate_steady_state.m index 6247d88ff..993148fc1 100644 --- a/matlab/evaluate_steady_state.m +++ b/matlab/evaluate_steady_state.m @@ -66,7 +66,7 @@ if options.ramsey_policy fprintf('\nevaluate_steady_state: The steady state file computation for the Ramsey problem resulted in NaNs.\n') fprintf('evaluate_steady_state: The steady state was computed conditional on the following initial instrument values: \n') for ii = 1:size(options.instruments,1) - fprintf('\t %s \t %f \n',options.instruments(ii,:),ys_init(strmatch(options.instruments(ii,:),M.endo_names,'exact'))) + fprintf('\t %s \t %f \n',options.instruments{ii},ys_init(strmatch(options.instruments{ii},M.endo_names,'exact'))) end fprintf('evaluate_steady_state: The problem occured in the following equations: \n') fprintf('\t Equation(s): ') @@ -87,7 +87,7 @@ if options.ramsey_policy fprintf('\nevaluate_steady_state: The steady state file computation for the Ramsey problem resulted in complex numbers.\n') fprintf('evaluate_steady_state: The steady state was computed conditional on the following initial instrument values: \n') for ii = 1:size(options.instruments,1) - fprintf('\t %s \t %f \n',options.instruments(ii,:),ys_init(strmatch(options.instruments(ii,:),M.endo_names,'exact'))) + fprintf('\t %s \t %f \n',options.instruments{ii},ys_init(strmatch(options.instruments{ii},M.endo_names,'exact'))) end fprintf('evaluate_steady_state: If those initial values are not admissable, change them using an initval-block.\n') skipline(2) @@ -102,7 +102,7 @@ if options.ramsey_policy fprintf('\nevaluate_steady_state: The steady state file does not solve the steady state for the Ramsey problem.\n') fprintf('evaluate_steady_state: Conditional on the following instrument values: \n') for ii = 1:size(options.instruments,1) - fprintf('\t %s \t %f \n',options.instruments(ii,:),ys_init(strmatch(options.instruments(ii,:),M.endo_names,'exact'))) + fprintf('\t %s \t %f \n',options.instruments{ii},ys_init(strmatch(options.instruments{ii},M.endo_names,'exact'))) end fprintf('evaluate_steady_state: the following equations have non-zero residuals: \n') for ii=n_multipliers+1:M.endo_nbr @@ -150,7 +150,7 @@ if options.ramsey_policy fprintf('\nevaluate_steady_state: The steady state computation for the Ramsey problem resulted in NaNs.\n') fprintf('evaluate_steady_state: The steady state computation resulted in the following instrument values: \n') for i = 1:size(options.instruments,1) - fprintf('\t %s \t %f \n',options.instruments(i,:),ys(strmatch(options.instruments(i,:),M.endo_names,'exact'))) + fprintf('\t %s \t %f \n',options.instruments{i},ys(strmatch(options.instruments{i},M.endo_names,'exact'))) end fprintf('evaluate_steady_state: The problem occured in the following equations: \n') fprintf('\t Equation(s): ') @@ -168,7 +168,7 @@ if options.ramsey_policy fprintf('\nevaluate_steady_state: The steady state computation for the Ramsey problem resulted in NaNs in the auxiliary equations.\n') fprintf('evaluate_steady_state: The steady state computation resulted in the following instrument values: \n') for i = 1:size(options.instruments,1) - fprintf('\t %s \t %f \n',options.instruments(i,:),ys(strmatch(options.instruments(i,:),M.endo_names,'exact'))) + fprintf('\t %s \t %f \n',options.instruments{i},ys(strmatch(options.instruments{i},M.endo_names,'exact'))) end fprintf('evaluate_steady_state: The problem occured in the following equations: \n') fprintf('\t Auxiliary equation(s): ') @@ -186,7 +186,7 @@ if options.ramsey_policy fprintf('\nevaluate_steady_state: The steady state for the Ramsey problem could not be computed.\n') fprintf('evaluate_steady_state: The steady state computation stopped with the following instrument values:: \n') for i = 1:size(options.instruments,1) - fprintf('\t %s \t %f \n',options.instruments(i,:),ys(strmatch(options.instruments(i,:),M.endo_names,'exact'))) + fprintf('\t %s \t %f \n',options.instruments{i},ys(strmatch(options.instruments{i},M.endo_names,'exact'))) end fprintf('evaluate_steady_state: The following equations have non-zero residuals: \n') for ii=1:n_multipliers