From 0c01c31491d162d7317888040c8f76a9bfa06a01 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Tue, 26 Nov 2019 17:05:14 +0100 Subject: [PATCH] Remove global variables from user-defined steady state files M_ and options_ are now passed as an input; params is an output as in the _steadystate2.m files --- examples/NK_baseline_steadystate.m | 12 +++++++----- matlab/evaluate_steady_state_file.m | 3 +-- tests/expectations/expectation_ss_old_steadystate.m | 7 ++++--- tests/steady_state/walsh1_old_ss_steadystate.m | 8 ++++---- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/examples/NK_baseline_steadystate.m b/examples/NK_baseline_steadystate.m index d2f88af93..02f70fe53 100644 --- a/examples/NK_baseline_steadystate.m +++ b/examples/NK_baseline_steadystate.m @@ -1,19 +1,20 @@ -function [ys,check] = NK_baseline_steadystate(ys,exo) -% function [ys,check] = NK_baseline_steadystate(ys,exo) +function [ys,params,check] = NK_baseline_steadystate(ys,exo,M_,options_) +% function [ys,params,check] = NK_baseline_steadystate(ys,exo,M_,options_) % computes the steady state for the NK_baseline.mod and uses a numerical % solver to do so % Inputs: % - ys [vector] vector of initial values for the steady state of % the endogenous variables % - exo [vector] vector of values for the exogenous variables +% - M_ [structure] Dynare model structure +% - options [structure] Dynare options structure % % Output: % - ys [vector] vector of steady state values for the the endogenous variables +% - params [vector] vector of parameter values % - check [scalar] set to 0 if steady state computation worked and to % 1 of not (allows to impose restrictions on parameters) -global M_ - % read out parameters to access them with their name NumberOfParameters = M_.param_nbr; for ii = 1:NumberOfParameters @@ -95,8 +96,9 @@ g2=epsilon/(epsilon-1)*g1; %% end own model equations +params=NaN(NumberOfParameters,1); for iter = 1:length(M_.params) %update parameters set in the file - eval([ 'M_.params(' num2str(iter) ') = ' M_.param_names{iter} ';' ]) + eval([ 'params(' num2str(iter) ') = ' M_.param_names{iter} ';' ]) end NumberOfEndogenousVariables = M_.orig_endo_nbr; %auxiliary variables are set automatically diff --git a/matlab/evaluate_steady_state_file.m b/matlab/evaluate_steady_state_file.m index 08213b7a6..7a299f0fa 100644 --- a/matlab/evaluate_steady_state_file.m +++ b/matlab/evaluate_steady_state_file.m @@ -46,8 +46,7 @@ if options.steadystate_flag == 1 assignin('base','tmp_00_',params); evalin('base','M_.params=tmp_00_; clear(''tmp_00_'')'); h_steadystate = str2func([fname '_steadystate']); - [ys,check] = h_steadystate(ys_init, exo_ss); - params1 = evalin('base','M_.params'); + [ys,params1,check] = h_steadystate(ys_init, exo_ss,M,options); else % steadystate_flag == 2 % new format h_steadystate = str2func([fname '.steadystate']); diff --git a/tests/expectations/expectation_ss_old_steadystate.m b/tests/expectations/expectation_ss_old_steadystate.m index bfd46d82a..fb5a88426 100644 --- a/tests/expectations/expectation_ss_old_steadystate.m +++ b/tests/expectations/expectation_ss_old_steadystate.m @@ -1,12 +1,13 @@ -function [ys_, check_] = expectation_ss_old_steadystate(ys_orig_, exo_) +function [ys_, params, check_] = expectation_ss_old_steadystate(ys_orig_, exo_,M_,options_) ys_=zeros(6,1); - global M_ + params=NaN(size(M_.params)); + params=M_.params; ys_(4)=0; ys_(6)=0; ys_(5)=0.3333333333333333; ys_(3)=((1/M_.params(1)-(1-M_.params(4)))/(M_.params(3)*ys_(5)^(1-M_.params(3))))^(1/(M_.params(3)-1)); ys_(1)=ys_(5)^(1-M_.params(3))*ys_(3)^M_.params(3); ys_(2)=ys_(1)-M_.params(4)*ys_(3); - M_.params(5)=(1-M_.params(3))*ys_(1)/(ys_(2)*ys_(5)^(1+M_.params(6))); + params(5)=(1-M_.params(3))*ys_(1)/(ys_(2)*ys_(5)^(1+M_.params(6))); check_=0; end diff --git a/tests/steady_state/walsh1_old_ss_steadystate.m b/tests/steady_state/walsh1_old_ss_steadystate.m index cc09a2d2f..6543d0618 100644 --- a/tests/steady_state/walsh1_old_ss_steadystate.m +++ b/tests/steady_state/walsh1_old_ss_steadystate.m @@ -1,5 +1,4 @@ -function [ys,check] = walsh1_old_ss_steadystate(ys,exo) -global M_ +function [ys,params,check] = walsh1_old_ss_steadystate(ys,exo,M_,options_) % read out parameters to access them with their name NumberOfParameters = M_.param_nbr; @@ -34,8 +33,9 @@ check = 0; %% end own model equations -for iter = 1:length(M_.params) %update parameters set in the file - eval([ 'M_.params(' num2str(iter) ') = ' M_.param_names{iter} ';' ]) +params=NaN(NumberOfParameters,1); +for iter = 1:NumberOfParameters %update parameters set in the file + eval([ 'params(' num2str(iter) ') = ' M_.param_names{iter} ';' ]) end NumberOfEndogenousVariables = M_.orig_endo_nbr; %auxiliary variables are set automatically