2023-10-25 17:29:55 +02:00
function [ys,params,info] = evaluate_steady_state ( ys_init,exo_ss,M_,options_,steadystate_check_flag)
% function [ys,params,info] = evaluate_steady_state(ys_init,exo_ss,M_,options_,steadystate_check_flag)
2012-03-06 19:05:59 +01:00
% Computes the steady state
%
2011-10-12 21:46:50 +02:00
% INPUTS
% ys_init vector initial values used to compute the steady
% state
2023-06-07 17:18:18 +02:00
% exo_ss vector exogenous steady state (incl. deterministic exogenous)
2023-10-25 17:29:55 +02:00
% M_ struct model structure
% options_ struct options
2011-10-12 21:46:50 +02:00
% steadystate_check_flag boolean if true, check that the
% steadystate verifies the
2012-03-06 19:05:59 +01:00
% static model
%
2011-10-12 21:46:50 +02:00
% OUTPUTS
2016-04-10 19:18:41 +02:00
% ys vector steady state (in declaration order)
2011-10-12 21:46:50 +02:00
% params vector model parameters possibly
% modified by user steadystate
% function
% info 2x1 vector error codes
%
% SPECIAL REQUIREMENTS
% none
2023-01-10 16:05:33 +01:00
% Copyright © 2001-2023 Dynare Team
2011-10-12 21:46:50 +02:00
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
2021-06-09 17:33:48 +02:00
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
2011-10-12 21:46:50 +02:00
2023-10-25 17:29:55 +02:00
if options_ . solve_algo < 0 || options_ . solve_algo > 14
2022-04-29 14:56:16 +02:00
error ( ' STEADY: solve_algo must be between 0 and 14' )
end
2023-10-25 17:29:55 +02:00
if ~ options_ . bytecode && ~ options_ . block && options_ . solve_algo > 4 && ...
options_ . solve_algo < 9
error ( ' STEADY: you can' ' t use solve_algo = {5,6,7,8} without block nor bytecode options_' )
2022-04-29 14:56:16 +02:00
end
2023-10-25 17:29:55 +02:00
if ~ options_ . bytecode && options_ . block && options_ . solve_algo == 5
2022-04-29 14:56:16 +02:00
error ( ' STEADY: you can' ' t use solve_algo = 5 without bytecode option' )
end
2023-10-25 17:29:55 +02:00
if isoctave && options_ . solve_algo == 11
2023-12-18 10:49:49 +01:00
error ( ' STEADY: you can' ' t use solve_algo = %u under Octave' , options_ . solve_algo )
2022-04-29 14:56:16 +02:00
end
2023-09-01 14:50:38 +02:00
% To ensure that the z and zx matrices constructed by repmat and passed to bytecode
% are of the right size.
if size ( ys_init , 2 ) > 1
error ( ' ys_init must be a column-vector' )
end
if size ( exo_ss , 2 ) > 1
error ( ' exo_ss must be a column-vector' )
end
2017-05-16 15:10:20 +02:00
info = 0 ;
check = 0 ;
2012-03-06 19:05:59 +01:00
2023-10-25 17:29:55 +02:00
steadystate_flag = options_ . steadystate_flag ;
params = M_ . params ;
2012-03-06 19:05:59 +01:00
2023-10-25 17:29:55 +02:00
if length ( M_ . aux_vars ) > 0 && ~ steadystate_flag && M_ . set_auxiliary_variables
h_set_auxiliary_variables = str2func ( [ M_ . fname ' .set_auxiliary_variables' ] ) ;
2018-11-14 16:01:55 +01:00
ys_init = h_set_auxiliary_variables ( ys_init , exo_ss , params ) ;
2017-05-16 15:10:20 +02:00
end
2012-03-06 19:05:59 +01:00
2023-10-25 17:29:55 +02:00
if options_ . ramsey_policy
if ~ isfinite ( M_ . params ( strmatch ( ' optimal_policy_discount_factor' , M_ . param_names , ' exact' ) ) )
2022-06-27 11:17:15 +02:00
fprintf ( ' \nevaluate_steady_state: the planner_discount is NaN/Inf. That will cause problems.\n' )
end
2017-05-16 15:10:20 +02:00
if steadystate_flag
% explicit steady state file
2023-10-25 17:29:55 +02:00
[ ys , params , info ] = evaluate_steady_state_file ( ys_init , exo_ss , M_ , ...
options_ , steadystate_check_flag ) ;
2017-05-16 15:10:20 +02:00
%test whether it solves model conditional on the instruments
2023-10-25 17:29:55 +02:00
if ~ options_ . debug
resids = evaluate_static_model ( ys , exo_ss , params , M_ , options_ ) ;
2021-11-05 12:22:43 +01:00
else
2023-10-25 17:29:55 +02:00
[ resids , ~ , jacob ] = evaluate_static_model ( ys , exo_ss , params , M_ , options_ ) ;
2021-11-05 12:22:43 +01:00
end
2023-10-25 17:29:55 +02:00
nan_indices = find ( isnan ( resids ( M_ . ramsey_orig_endo_nbr + ( 1 : M_ . ramsey_orig_eq_nbr ) ) ) ) ;
2014-07-18 12:41:28 +02:00
if ~ isempty ( nan_indices )
2023-10-25 17:29:55 +02:00
if options_ . debug
2017-05-16 15:10:20 +02:00
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' )
2023-10-25 17:29:55 +02:00
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' ) ) )
2016-08-10 12:28:23 +02:00
end
fprintf ( ' evaluate_steady_state: The problem occured in the following equations: \n' )
fprintf ( ' \t Equation(s): ' )
for ii = 1 : length ( nan_indices )
2014-07-18 12:41:28 +02:00
fprintf ( ' %d, ' , nan_indices ( ii ) ) ;
2016-08-10 12:28:23 +02:00
end
2017-05-16 12:42:01 +02:00
skipline ( )
2017-05-16 15:10:20 +02:00
fprintf ( ' evaluate_steady_state: If those initial values are not admissable, change them using an initval-block.\n' )
skipline ( 2 )
2014-07-18 12:41:28 +02:00
end
2017-05-16 15:10:20 +02:00
info ( 1 ) = 84 ;
info ( 2 ) = resids ' * resids ;
2017-05-16 12:42:01 +02:00
return
2014-07-18 12:41:28 +02:00
end
2023-10-25 17:29:55 +02:00
if any ( imag ( ys ( M_ . ramsey_orig_endo_nbr + ( 1 : M_ . ramsey_orig_eq_nbr ) ) ) )
if options_ . debug
2017-05-16 15:10:20 +02:00
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' )
2023-10-25 17:29:55 +02:00
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' ) ) )
2016-08-10 12:28:23 +02:00
end
2017-05-16 15:10:20 +02:00
fprintf ( ' evaluate_steady_state: If those initial values are not admissable, change them using an initval-block.\n' )
skipline ( 2 )
2014-07-18 12:41:28 +02:00
end
2017-05-16 15:10:20 +02:00
info ( 1 ) = 86 ;
info ( 2 ) = resids ' * resids ;
2017-05-16 12:42:01 +02:00
return
2014-07-18 12:41:28 +02:00
end
2023-10-25 17:29:55 +02:00
if max ( abs ( resids ( M_ . ramsey_orig_endo_nbr + ( 1 : M_ . ramsey_orig_eq_nbr ) ) ) ) > options_ . solve_tolf %does it solve for all variables except for the Lagrange multipliers
if options_ . debug
2017-05-16 15:10:20 +02:00
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' )
2023-10-25 17:29:55 +02:00
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' ) ) )
2016-08-10 12:28:23 +02:00
end
2017-05-16 15:10:20 +02:00
fprintf ( ' evaluate_steady_state: the following equations have non-zero residuals: \n' )
2023-10-25 17:29:55 +02:00
for ii = M_ . ramsey_orig_endo_nbr + 1 : M_ . endo_nbr
if abs ( resids ( ii ) ) > options_ . solve_tolf
fprintf ( ' \t Equation number %d: %f\n' , ii - M_ . ramsey_orig_endo_nbr , resids ( ii ) )
2016-08-10 12:28:23 +02:00
end
2014-07-18 12:41:28 +02:00
end
2017-05-16 12:42:01 +02:00
skipline ( 2 )
2014-07-18 12:41:28 +02:00
end
2017-05-16 15:10:20 +02:00
info ( 1 ) = 85 ;
2014-10-10 21:46:50 +02:00
info ( 2 ) = resids ' * resids ;
2017-05-16 12:42:01 +02:00
return
2014-10-10 21:46:50 +02:00
end
2017-05-16 15:10:20 +02:00
end
2023-10-25 17:29:55 +02:00
if options_ . debug
2021-12-17 14:57:41 +01:00
if steadystate_flag
2023-10-25 17:29:55 +02:00
infrow = find ( isinf ( ys_init ( 1 : M_ . orig_endo_nbr ) ) ) ;
2021-12-17 14:57:41 +01:00
else
infrow = find ( isinf ( ys_init ) ) ;
end
2017-05-16 15:10:20 +02:00
if ~ isempty ( infrow )
fprintf ( ' \nevaluate_steady_state: The initial values for the steady state of the following variables are Inf:\n' ) ;
for iter = 1 : length ( infrow )
2023-10-25 17:29:55 +02:00
fprintf ( ' %s\n' , M_ . endo_names { infrow ( iter ) } ) ;
2017-05-16 15:10:20 +02:00
end
2012-04-21 11:39:21 +02:00
end
2021-12-17 14:57:41 +01:00
if steadystate_flag
2023-10-25 17:29:55 +02:00
nanrow = find ( isnan ( ys_init ( 1 : M_ . orig_endo_nbr ) ) ) ;
2021-12-17 14:57:41 +01:00
else
nanrow = find ( isnan ( ys_init ) ) ;
end
2017-05-16 15:10:20 +02:00
if ~ isempty ( nanrow )
fprintf ( ' \nevaluate_steady_state: The initial values for the steady state of the following variables are NaN:\n' ) ;
for iter = 1 : length ( nanrow )
2023-10-25 17:29:55 +02:00
fprintf ( ' %s\n' , M_ . endo_names { nanrow ( iter ) } ) ;
2016-08-21 11:45:11 +02:00
end
2017-05-16 15:10:20 +02:00
end
2021-12-10 09:05:55 +01:00
if steadystate_flag
2023-10-25 17:29:55 +02:00
nan_indices_mult = find ( isnan ( resids ( 1 : M_ . ramsey_orig_endo_nbr ) ) ) ;
2021-12-10 09:05:55 +01:00
if any ( nan_indices_mult )
fprintf ( ' evaluate_steady_state: The steady state results NaN for auxiliary equation %u.\n' , nan_indices_mult ) ;
fprintf ( ' evaluate_steady_state: This is often a sign of problems.\n' ) ;
end
[ infrow , infcol ] = find ( isinf ( jacob ) ) ;
if ~ isempty ( infrow )
fprintf ( ' \nevaluate_steady_state: The Jacobian of the dynamic model contains Inf. The problem is associated with:\n\n' )
2023-10-25 17:29:55 +02:00
display_problematic_vars_Jacobian ( infrow , infcol , M_ , ys , ' static' , ' evaluate_steady_state: ' )
2021-12-10 09:05:55 +01:00
end
if ~ isreal ( jacob )
[ imagrow , imagcol ] = find ( abs ( imag ( jacob ) ) > 1e-15 ) ;
fprintf ( ' \nevaluate_steady_state: The Jacobian of the dynamic model contains imaginary parts. The problem arises from: \n\n' )
2023-10-25 17:29:55 +02:00
display_problematic_vars_Jacobian ( imagrow , imagcol , M_ , ys , ' static' , ' evaluate_steady_state: ' )
2021-12-10 09:05:55 +01:00
end
[ nanrow , nancol ] = find ( isnan ( jacob ) ) ;
if ~ isempty ( nanrow )
fprintf ( ' \nevaluate_steady_state: The Jacobian of the dynamic model contains NaN. The problem is associated with:\n\n' )
2023-10-25 17:29:55 +02:00
display_problematic_vars_Jacobian ( nanrow , nancol , M_ , ys , ' static' , ' evaluate_steady_state: ' )
2021-12-10 09:05:55 +01:00
end
2021-11-05 12:22:43 +01:00
end
2017-05-16 15:10:20 +02:00
end
%either if no steady state file or steady state file without problems
2023-10-25 17:29:55 +02:00
[ ys , params , info ] = dyn_ramsey_static ( ys_init , exo_ss , M_ , options_ ) ;
2017-05-16 15:10:20 +02:00
if info
return
end
%check whether steady state really solves the model
2023-10-25 17:29:55 +02:00
resids = evaluate_static_model ( ys , exo_ss , params , M_ , options_ ) ;
2013-06-01 16:32:40 +02:00
2023-10-25 17:29:55 +02:00
nan_indices_multiplier = find ( isnan ( resids ( 1 : M_ . ramsey_orig_endo_nbr ) ) ) ;
nan_indices = find ( isnan ( resids ( M_ . ramsey_orig_endo_nbr + 1 : end ) ) ) ;
2017-05-16 15:10:20 +02:00
if ~ isempty ( nan_indices )
2023-10-25 17:29:55 +02:00
if options_ . debug
2017-05-16 15:10:20 +02:00
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' )
2023-10-25 17:29:55 +02:00
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' ) ) )
2011-10-12 21:46:50 +02:00
end
2017-05-16 15:10:20 +02:00
fprintf ( ' evaluate_steady_state: The problem occured in the following equations: \n' )
fprintf ( ' \t Equation(s): ' )
for ii = 1 : length ( nan_indices )
fprintf ( ' %d, ' , nan_indices ( ii ) ) ;
2013-07-28 00:09:11 +02:00
end
2017-05-16 15:10:20 +02:00
skipline ( )
2011-10-12 21:46:50 +02:00
end
2017-05-16 15:10:20 +02:00
info ( 1 ) = 82 ;
return
2011-10-12 21:46:50 +02:00
end
2017-05-16 15:10:20 +02:00
if ~ isempty ( nan_indices_multiplier )
2023-10-25 17:29:55 +02:00
if options_ . debug
2017-05-16 15:10:20 +02:00
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' )
2023-10-25 17:29:55 +02:00
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' ) ) )
2017-05-16 15:10:20 +02:00
end
fprintf ( ' evaluate_steady_state: The problem occured in the following equations: \n' )
fprintf ( ' \t Auxiliary equation(s): ' )
for ii = 1 : length ( nan_indices_multiplier )
fprintf ( ' %d, ' , nan_indices_multiplier ( ii ) ) ;
end
skipline ( )
2016-10-13 10:50:50 +02:00
end
2017-05-16 15:10:20 +02:00
info ( 1 ) = 83 ;
return
end
2023-10-25 17:29:55 +02:00
if max ( abs ( resids ) ) > options_ . solve_tolf %does it solve for all variables including the auxiliary ones
if options_ . debug
2017-05-16 15:10:20 +02:00
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' )
2023-10-25 17:29:55 +02:00
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' ) ) )
2017-05-16 15:10:20 +02:00
end
fprintf ( ' evaluate_steady_state: The following equations have non-zero residuals: \n' )
2023-10-25 17:29:55 +02:00
for ii = 1 : M_ . ramsey_orig_endo_nbr
if abs ( resids ( ii ) ) > options_ . solve_tolf / 100
2017-05-16 15:10:20 +02:00
fprintf ( ' \t Auxiliary Ramsey equation number %d: %f\n' , ii , resids ( ii ) )
end
end
2023-10-25 17:29:55 +02:00
for ii = M_ . ramsey_orig_endo_nbr + 1 : M_ . endo_nbr
if abs ( resids ( ii ) ) > options_ . solve_tolf / 100
fprintf ( ' \t Equation number %d: %f\n' , ii - M_ . ramsey_orig_endo_nbr , resids ( ii ) )
2017-05-16 15:10:20 +02:00
end
end
skipline ( 2 )
2013-06-01 16:32:40 +02:00
end
2017-05-16 15:10:20 +02:00
info ( 1 ) = 81 ;
info ( 2 ) = resids ' * resids ;
return
end
elseif steadystate_flag
% explicit steady state file
2023-10-25 17:29:55 +02:00
[ ys , params , info ] = evaluate_steady_state_file ( ys_init , exo_ss , M_ , options_ , steadystate_check_flag ) ;
2017-05-16 15:10:20 +02:00
if size ( ys , 2 ) > size ( ys , 1 )
error ( ' STEADY: steady_state-file must return a column vector, not a row vector.' )
end
if info ( 1 )
2011-10-12 21:46:50 +02:00
return
end
2023-10-25 17:29:55 +02:00
elseif ~ options_ . bytecode && ~ options_ . block
static_resid = str2func ( sprintf ( ' %s.sparse.static_resid' , M_ . fname ) ) ;
static_g1 = str2func ( sprintf ( ' %s.sparse.static_g1' , M_ . fname ) ) ;
if ~ options_ . linear
2021-06-22 12:29:39 +02:00
% non linear model
2023-10-25 17:29:55 +02:00
if ismember ( options_ . solve_algo , [ 10 , 11 ] )
[ lb , ub , eq_index ] = get_complementarity_conditions ( M_ , options_ . ramsey_policy ) ;
if options_ . solve_algo == 10
options_ . lmmcp . lb = lb ;
options_ . lmmcp . ub = ub ;
elseif options_ . solve_algo == 11
options_ . mcppath . lb = lb ;
options_ . mcppath . ub = ub ;
2021-06-22 12:29:39 +02:00
end
2023-08-27 11:25:29 +02:00
[ ys , check , fvec , fjac , errorcode ] = dynare_solve ( @ static_mcp_problem , ...
2021-06-22 12:29:39 +02:00
ys_init , ...
2023-10-25 17:29:55 +02:00
options_ . steady . maxit , options_ . solve_tolf , options_ . solve_tolx , ...
options_ , exo_ss , params , ...
M_ . endo_nbr , static_resid , static_g1 , ...
M_ . static_g1_sparse_rowval , M_ . static_g1_sparse_colval , M_ . static_g1_sparse_colptr , eq_index ) ;
2021-06-22 12:29:39 +02:00
else
2023-08-27 11:25:29 +02:00
[ ys , check , fvec , fjac , errorcode ] = dynare_solve ( @ static_problem , ys_init , ...
2023-10-25 17:29:55 +02:00
options_ . steady . maxit , options_ . solve_tolf , options_ . solve_tolx , ...
options_ , exo_ss , params , M_ . endo_nbr , static_resid , static_g1 , ...
M_ . static_g1_sparse_rowval , M_ . static_g1_sparse_colval , M_ . static_g1_sparse_colptr ) ;
2021-06-22 12:29:39 +02:00
end
2023-10-25 17:29:55 +02:00
if check && options_ . debug
2022-04-09 16:03:37 +02:00
dprintf ( ' Nonlinear solver routine returned errorcode=%i.' , errorcode )
skipline ( )
2017-05-16 15:10:20 +02:00
[ infrow , infcol ] = find ( isinf ( fjac ) | isnan ( fjac ) ) ;
if ~ isempty ( infrow )
fprintf ( ' \nSTEADY: The Jacobian at the initial values contains Inf or NaN. The problem arises from: \n' )
2023-10-25 17:29:55 +02:00
display_problematic_vars_Jacobian ( infrow , infcol , M_ , ys_init , ' static' , ' STEADY: ' )
2017-05-16 15:10:20 +02:00
end
problematic_equation = find ( ~ isfinite ( fvec ) ) ;
if ~ isempty ( problematic_equation )
fprintf ( ' \nSTEADY: numerical initial values or parameters incompatible with the following equations\n' )
disp ( problematic_equation ' )
fprintf ( ' Please check for example\n' )
fprintf ( ' i) if all parameters occurring in these equations are defined\n' )
fprintf ( ' ii) that no division by an endogenous variable initialized to 0 occurs\n' )
end
end
else
% linear model
2023-01-10 16:05:33 +01:00
[ fvec , T_order , T ] = static_resid ( ys_init , exo_ss , params ) ;
2023-10-25 17:29:55 +02:00
jacob = static_g1 ( ys_init , exo_ss , params , M_ . static_g1_sparse_rowval , M_ . static_g1_sparse_colval , M_ . static_g1_sparse_colptr , T_order , T ) ;
2011-10-12 21:46:50 +02:00
2017-05-16 15:10:20 +02:00
ii = find ( ~ isfinite ( fvec ) ) ;
if ~ isempty ( ii )
ys = fvec ;
check = 1 ;
disp ( [ ' STEADY: numerical initial values or parameters incompatible with the following' ...
' equations' ] )
disp ( ii ' )
2017-06-11 10:58:19 +02:00
disp ( ' Check whether your model is truly linear. Put "resid(1);" before "steady;" to see the problematic equations.' )
2017-05-16 15:10:20 +02:00
elseif isempty ( ii ) && max ( abs ( fvec ) ) > 1e-12
ys = ys_init - jacob \ fvec ;
2023-10-25 17:29:55 +02:00
resid = evaluate_static_model ( ys , exo_ss , params , M_ , options_ ) ;
2017-05-16 15:10:20 +02:00
if max ( abs ( resid ) ) > 1e-6
check = 1 ;
fprintf ( ' STEADY: No steady state for your model could be found\n' )
fprintf ( ' STEADY: Check whether your model is truly linear. Put "resid(1);" before "steady;" to see the problematic equations.\n' )
end
2013-04-11 17:07:39 +02:00
else
2017-05-16 15:10:20 +02:00
ys = ys_init ;
2013-04-11 17:07:39 +02:00
end
2023-10-25 17:29:55 +02:00
if options_ . debug
2017-05-16 15:10:20 +02:00
if any ( any ( isinf ( jacob ) | isnan ( jacob ) ) )
[ infrow , infcol ] = find ( isinf ( jacob ) | isnan ( jacob ) ) ;
fprintf ( ' \nSTEADY: The Jacobian contains Inf or NaN. The problem arises from: \n\n' )
for ii = 1 : length ( infrow )
2023-10-25 17:29:55 +02:00
fprintf ( ' STEADY: Derivative of Equation %d with respect to Variable %s (initial value of %s: %g) \n' , infrow ( ii ) , M_ . endo_names { infcol ( ii ) , : } , M_ . endo_names { infcol ( ii ) , : } , ys_init ( infcol ( ii ) ) )
2017-05-16 15:10:20 +02:00
end
fprintf ( ' Check whether your model is truly linear. Put "resid(1);" before "steady;" to see the problematic equations.\n' )
end
2013-04-11 17:07:39 +02:00
end
end
2023-10-25 17:29:55 +02:00
elseif ~ options_ . bytecode && options_ . block
2023-01-17 15:25:47 +01:00
ys = ys_init ;
2023-10-25 17:29:55 +02:00
T = NaN ( M_ . block_structure_stat . tmp_nbr , 1 ) ;
for b = 1 : length ( M_ . block_structure_stat . block )
fh_static = str2func ( sprintf ( ' %s.sparse.block.static_%d' , M_ . fname , b ) ) ;
if M_ . block_structure_stat . block ( b ) . Simulation_Type ~= 1 && ...
M_ . block_structure_stat . block ( b ) . Simulation_Type ~= 2
mfs_idx = M_ . block_structure_stat . block ( b ) . variable ( end - M_ . block_structure_stat . block ( b ) . mfs + 1 : end ) ;
if options_ . solve_algo < = 4 || options_ . solve_algo > = 9
2023-01-17 19:05:04 +01:00
[ ys ( mfs_idx ) , errorflag ] = dynare_solve ( @ block_mfs_steadystate , ys ( mfs_idx ) , ...
2023-10-25 17:29:55 +02:00
options_ . steady . maxit , options_ . solve_tolf , options_ . solve_tolx , ...
options_ , fh_static , b , ys , exo_ss , params , T , M_ ) ;
2023-01-17 15:25:47 +01:00
if errorflag
check = 1 ;
break
end
else
2023-10-25 17:29:55 +02:00
nze = length ( M_ . block_structure_stat . block ( b ) . g1_sparse_rowval ) ;
2023-06-06 18:13:10 +02:00
[ ys , T , success ] = solve_one_boundary ( fh_static , ys , exo_ss , ...
2023-10-25 17:29:55 +02:00
params , [ ] , T , mfs_idx , nze , 1 , false , b , 0 , options_ . steady . maxit , ...
options_ . solve_tolf , ...
0 , options_ . solve_algo , true , false , false , M_ , options_ ) ;
2023-06-06 18:13:10 +02:00
if ~ success
2023-01-17 15:25:47 +01:00
check = 1 ;
break
end
end
end
% Compute endogenous if the block is of type evaluate forward/backward or if there are recursive variables in a solve block.
% Also update the temporary terms vector (needed for the dynare_solve case)
2023-10-25 17:29:55 +02:00
[ ys , T ] = fh_static ( ys , exo_ss , params , M_ . block_structure_stat . block ( b ) . g1_sparse_rowval , ...
M_ . block_structure_stat . block ( b ) . g1_sparse_colval , ...
M_ . block_structure_stat . block ( b ) . g1_sparse_colptr , T ) ;
2023-01-17 15:25:47 +01:00
end
2023-10-25 17:29:55 +02:00
elseif options_ . bytecode
if options_ . solve_algo > = 5 && options_ . solve_algo < = 8
2023-01-17 15:25:47 +01:00
try
2023-10-25 17:29:55 +02:00
if options_ . block
ys = bytecode ( ' static' , ' block_decomposed' , M_ , options_ , ys_init , exo_ss , params ) ;
2023-01-17 15:25:47 +01:00
else
2023-10-25 17:29:55 +02:00
ys = bytecode ( ' static' , M_ , options_ , ys_init , exo_ss , params ) ;
2023-01-17 15:25:47 +01:00
end
catch ME
2023-10-25 17:29:55 +02:00
if options_ . verbosity > = 1
2023-06-15 16:59:37 +02:00
disp ( ME . message ) ;
end
2023-06-14 16:29:51 +02:00
ys = ys_init ;
2023-01-17 15:25:47 +01:00
check = 1 ;
end
2023-10-25 17:29:55 +02:00
elseif options_ . block
2023-01-17 15:25:47 +01:00
ys = ys_init ;
2023-10-25 17:29:55 +02:00
T = NaN ( M_ . block_structure_stat . tmp_nbr , 1 ) ;
for b = 1 : length ( M_ . block_structure_stat . block )
if M_ . block_structure_stat . block ( b ) . Simulation_Type ~= 1 && ...
M_ . block_structure_stat . block ( b ) . Simulation_Type ~= 2
mfs_idx = M_ . block_structure_stat . block ( b ) . variable ( end - M_ . block_structure_stat . block ( b ) . mfs + 1 : end ) ;
2023-01-17 19:05:04 +01:00
[ ys ( mfs_idx ) , errorflag ] = dynare_solve ( @ block_bytecode_mfs_steadystate , ...
2023-10-25 17:29:55 +02:00
ys ( mfs_idx ) , options_ . steady . maxit , ...
options_ . solve_tolf , options_ . solve_tolx , ...
options_ , b , ys , exo_ss , params , T , M_ , options_ ) ;
2023-01-17 15:25:47 +01:00
if errorflag
check = 1 ;
break
end
end
% Compute endogenous if the block is of type evaluate forward/backward or if there are recursive variables in a solve block.
% Also update the temporary terms vector (needed for the dynare_solve case)
try
2023-10-25 17:29:55 +02:00
[ ~ , ~ , ys , T ] = bytecode ( M_ , options_ , ys , exo_ss , params , ys , 1 , ys , T , ' evaluate' , ' static' , ...
2023-11-02 16:35:31 +01:00
' block_decomposed' , [ ' block=' int2str ( b ) ] ) ;
2023-01-17 15:25:47 +01:00
catch ME
2023-10-25 17:29:55 +02:00
if options_ . verbosity > = 1
2023-06-15 16:59:37 +02:00
disp ( ME . message ) ;
end
2023-01-17 15:25:47 +01:00
check = 1 ;
break
end
end
else
2023-02-18 03:34:56 +01:00
[ ys , check ] = dynare_solve ( @ bytecode_steadystate , ys_init , ...
2023-10-25 17:29:55 +02:00
options_ . steady . maxit , options_ . solve_tolf , options_ . solve_tolx , ...
options_ , exo_ss , params , M_ , options_ ) ;
2023-01-17 15:25:47 +01:00
end
2017-05-16 15:10:20 +02:00
end
2014-10-10 21:46:50 +02:00
2017-05-16 15:10:20 +02:00
if check
info ( 1 ) = 20 ;
%make sure ys contains auxiliary variables in case of problem with dynare_solve
2023-10-25 17:29:55 +02:00
if length ( M_ . aux_vars ) > 0 && ~ steadystate_flag
if M_ . set_auxiliary_variables
2018-11-14 16:01:55 +01:00
ys = h_set_auxiliary_variables ( ys , exo_ss , params ) ;
2017-08-29 10:58:39 +02:00
end
2011-10-12 21:46:50 +02:00
end
2023-10-25 17:29:55 +02:00
resid = evaluate_static_model ( ys , exo_ss , params , M_ , options_ ) ;
2017-05-16 15:10:20 +02:00
info ( 2 ) = resid ' * resid ;
if isnan ( info ( 2 ) )
info ( 1 ) = 22 ;
end
return
end
2011-10-12 21:46:50 +02:00
2017-05-16 15:10:20 +02:00
% If some equations are tagged [static] or [dynamic], verify consistency
2023-10-25 17:29:55 +02:00
if M_ . static_and_dynamic_models_differ
2017-05-16 15:10:20 +02:00
% Evaluate residual of *dynamic* model using the steady state
% computed on the *static* one
2023-10-25 17:29:55 +02:00
if options_ . bytecode
z = repmat ( ys , 1 , M_ . maximum_lead + M_ . maximum_lag + 1 ) ;
zx = repmat ( exo_ss ' , M_ . maximum_lead + M_ . maximum_lag + 1 , 1 ) ;
r = bytecode ( ' dynamic' , ' evaluate' , M_ , options_ , z , zx , params , ys , 1 ) ;
2017-05-16 15:10:20 +02:00
else
2023-10-25 17:29:55 +02:00
r = feval ( [ M_ . fname ' .sparse.dynamic_resid' ] , repmat ( ys , 3 , 1 ) , exo_ss , params , ys ) ;
2017-05-16 15:10:20 +02:00
end
% Fail if residual greater than tolerance
2023-10-25 17:29:55 +02:00
if max ( abs ( r ) ) > options_ . solve_tolf
2017-05-16 15:10:20 +02:00
info ( 1 ) = 25 ;
2011-10-12 21:46:50 +02:00
return
end
2017-05-16 15:10:20 +02:00
end
if ~ isreal ( ys )
2022-11-07 10:14:33 +01:00
if sum ( imag ( ys ) .^ 2 ) < 1e-7
ys = real ( ys ) ;
else
info ( 1 ) = 21 ;
info ( 2 ) = sum ( imag ( ys ) .^ 2 ) ;
ys = real ( ys ) ;
2017-05-16 15:10:20 +02:00
return
2022-11-07 10:14:33 +01:00
end
2017-05-16 15:10:20 +02:00
end
if ~ isempty ( find ( isnan ( ys ) ) )
info ( 1 ) = 22 ;
info ( 2 ) = NaN ;
return
end
2016-03-21 11:51:48 +01:00
2023-01-10 16:05:33 +01:00
function [resids,jac] = static_problem ( y, x, params, nvar, fh_static_resid, fh_static_g1, sparse_rowval, sparse_colval, sparse_colptr)
[ r , T_order , T ] = fh_static_resid ( y , x , params ) ;
j = fh_static_g1 ( y , x , params , sparse_rowval , sparse_colval , sparse_colptr , T_order , T ) ;
2017-05-16 15:10:20 +02:00
resids = r ( 1 : nvar ) ;
jac = j ( 1 : nvar , 1 : nvar ) ;
2021-06-22 12:29:39 +02:00
2023-01-10 16:05:33 +01:00
function [resids,jac] = static_mcp_problem ( y, x, params, nvar, fh_static_resid, fh_static_g1, sparse_rowval, sparse_colval, sparse_colptr, eq_index)
[ r , T_order , T ] = fh_static_resid ( y , x , params ) ;
j = fh_static_g1 ( y , x , params , sparse_rowval , sparse_colval , sparse_colptr , T_order , T ) ;
2021-06-22 12:29:39 +02:00
resids = r ( eq_index ) ;
jac = j ( eq_index , 1 : nvar ) ;
2023-01-17 15:25:47 +01:00
2023-10-25 17:29:55 +02:00
function [r, g1] = block_mfs_steadystate ( y, fh_static, b, y_all, exo, params, T, M_)
2023-01-17 15:25:47 +01:00
% Wrapper around the static files, for block without bytecode
2023-10-25 17:29:55 +02:00
mfs_idx = M_ . block_structure_stat . block ( b ) . variable ( end - M_ . block_structure_stat . block ( b ) . mfs + 1 : end ) ;
2023-01-17 19:05:04 +01:00
y_all ( mfs_idx ) = y ;
2023-10-25 17:29:55 +02:00
[ ~ , ~ , r , g1 ] = fh_static ( y_all , exo , params , M_ . block_structure_stat . block ( b ) . g1_sparse_rowval , ...
M_ . block_structure_stat . block ( b ) . g1_sparse_colval , ...
M_ . block_structure_stat . block ( b ) . g1_sparse_colptr , T ) ;
2023-01-17 15:25:47 +01:00
2023-10-25 17:29:55 +02:00
function [r, g1] = bytecode_steadystate ( y, exo, params, M_, options_)
2023-02-18 03:34:56 +01:00
% Wrapper around the static file, for bytecode (without block)
2023-10-25 17:29:55 +02:00
[ r , g1 ] = bytecode ( M_ , options_ , y , exo , params , y , 1 , exo , ' evaluate' , ' static' ) ;
2023-02-18 03:34:56 +01:00
2023-10-25 17:29:55 +02:00
function [r, g1] = block_bytecode_mfs_steadystate ( y, b, y_all, exo, params, T, M_, options_)
2023-10-24 16:23:53 +02:00
% Wrapper around the static files, for bytecode with block
2023-10-25 17:29:55 +02:00
mfs_idx = M_ . block_structure_stat . block ( b ) . variable ( end - M_ . block_structure_stat . block ( b ) . mfs + 1 : end ) ;
2023-01-17 19:05:04 +01:00
y_all ( mfs_idx ) = y ;
2023-11-02 16:35:31 +01:00
[ r , g1 ] = bytecode ( M_ , options_ , y_all , exo , params , y_all , 1 , y_all , T , ' evaluate' , ' static' , ' block_decomposed' , [ ' block=' int2str ( b ) ] ) ;
2023-10-25 17:29:55 +02:00
g1 = g1 ( : , end - M_ . block_structure_stat . block ( b ) . mfs + 1 : end ) ; % Make Jacobian square if mfs>0