Display exitflag returned by fsolve.
When the Newton fails in the simulation of backward models.trustregion
parent
e6592b3943
commit
e815fb2901
|
@ -56,12 +56,12 @@ for it = initialconditions.nobs+(1:samplesize)
|
||||||
y = y_; % A good guess for the initial conditions is the previous values for the endogenous variables.
|
y = y_; % A good guess for the initial conditions is the previous values for the endogenous variables.
|
||||||
try
|
try
|
||||||
if ismember(DynareOptions.solve_algo, [12,14])
|
if ismember(DynareOptions.solve_algo, [12,14])
|
||||||
[DynareOutput.endo_simul(:,it), errorflag] = ...
|
[DynareOutput.endo_simul(:,it), errorflag, ~, ~, exitflag] = ...
|
||||||
dynare_solve(model_dynamic_s, y, DynareOptions, ...
|
dynare_solve(model_dynamic_s, y, DynareOptions, ...
|
||||||
DynareModel.isloggedlhs, DynareModel.isauxdiffloggedrhs, DynareModel.endo_names, DynareModel.lhs, ...
|
DynareModel.isloggedlhs, DynareModel.isauxdiffloggedrhs, DynareModel.endo_names, DynareModel.lhs, ...
|
||||||
model_dynamic, ylag, DynareOutput.exo_simul, DynareModel.params, DynareOutput.steady_state, it);
|
model_dynamic, ylag, DynareOutput.exo_simul, DynareModel.params, DynareOutput.steady_state, it);
|
||||||
else
|
else
|
||||||
[DynareOutput.endo_simul(:,it), errorflag] = ...
|
[DynareOutput.endo_simul(:,it), errorflag, ~, ~, exitflag] = ...
|
||||||
dynare_solve(model_dynamic_s, y, DynareOptions, ...
|
dynare_solve(model_dynamic_s, y, DynareOptions, ...
|
||||||
model_dynamic, ylag, DynareOutput.exo_simul, DynareModel.params, DynareOutput.steady_state, it);
|
model_dynamic, ylag, DynareOutput.exo_simul, DynareModel.params, DynareOutput.steady_state, it);
|
||||||
end
|
end
|
||||||
|
@ -130,8 +130,25 @@ for it = initialconditions.nobs+(1:samplesize)
|
||||||
display_names_of_problematic_equations(DynareModel, residuals_evaluating_to_nan);
|
display_names_of_problematic_equations(DynareModel, residuals_evaluating_to_nan);
|
||||||
skipline()
|
skipline()
|
||||||
end
|
end
|
||||||
% TODO Implement same checks with the jacobian matrix.
|
%
|
||||||
|
% Display value of exitflag if available (fsolve, solve_algo=0, only)
|
||||||
|
%
|
||||||
|
if ~isnan(exitflag)
|
||||||
|
skipline()
|
||||||
|
switch exitflag
|
||||||
|
case 0
|
||||||
|
dprint('Returned value for exitflag is 0 (maximum number of iterations or evaluation reached).')
|
||||||
|
case -1
|
||||||
|
dprint('Returned value for exitflag is -1 (objective function stopped algorithm).')
|
||||||
|
case -3
|
||||||
|
dprint('Returned value for exitflag is -3 (Trust region radius became too small, trust-region-dogleg algorithm).')
|
||||||
|
case -2
|
||||||
|
dprint('Returned value for exitflag is -2.')
|
||||||
|
end
|
||||||
|
end
|
||||||
break
|
break
|
||||||
|
% TODO Implement same checks with the jacobian matrix.
|
||||||
|
% TODO Modify other solvers to return an exitflag.
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
function [x, errorflag, fvec, fjac] = dynare_solve(f, x, options, varargin)
|
function [x, errorflag, fvec, fjac, exitflag] = dynare_solve(f, x, options, varargin)
|
||||||
|
|
||||||
% Solves a nonlinear system of equations, f(x) = 0 with n unknowns
|
% Solves a nonlinear system of equations, f(x) = 0 with n unknowns
|
||||||
% and n equations.
|
% and n equations.
|
||||||
|
@ -15,7 +15,7 @@ function [x, errorflag, fvec, fjac] = dynare_solve(f, x, options, varargin)
|
||||||
% - fvec [double] n×1 vector, function value at x (f(x), used for debugging when errorflag is true).
|
% - fvec [double] n×1 vector, function value at x (f(x), used for debugging when errorflag is true).
|
||||||
% - fjac [double] n×n matrix, Jacobian value at x (J(x), used for debugging when errorflag is true).
|
% - fjac [double] n×n matrix, Jacobian value at x (J(x), used for debugging when errorflag is true).
|
||||||
|
|
||||||
% Copyright © 2001-2021 Dynare Team
|
% Copyright © 2001-2022 Dynare Team
|
||||||
%
|
%
|
||||||
% This file is part of Dynare.
|
% This file is part of Dynare.
|
||||||
%
|
%
|
||||||
|
@ -32,6 +32,8 @@ function [x, errorflag, fvec, fjac] = dynare_solve(f, x, options, varargin)
|
||||||
% You should have received a copy of the GNU General Public License
|
% You should have received a copy of the GNU General Public License
|
||||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
exitflag = nan;
|
||||||
|
|
||||||
jacobian_flag = options.jacobian_flag; % true iff Jacobian is returned by f routine (as a second output argument).
|
jacobian_flag = options.jacobian_flag; % true iff Jacobian is returned by f routine (as a second output argument).
|
||||||
|
|
||||||
% Set tolerance parameter depending the the caller function.
|
% Set tolerance parameter depending the the caller function.
|
||||||
|
|
Loading…
Reference in New Issue