diff --git a/matlab/solve1.m b/matlab/solve1.m index 265f388c4..4b721aaff 100644 --- a/matlab/solve1.m +++ b/matlab/solve1.m @@ -1,4 +1,5 @@ -function [x,check] = solve1(func,x,j1,j2,jacobian_flag,gstep,tolf,tolx,maxit,fake,debug,varargin) +function [x, errorflag] = solve1(func, x, j1, j2, jacobian_flag, gstep, tolf, tolx, maxit, fake, debug, varargin) + % Solves systems of non linear equations of several variables % % INPUTS @@ -19,12 +20,12 @@ function [x,check] = solve1(func,x,j1,j2,jacobian_flag,gstep,tolf,tolx,maxit,fak % % OUTPUTS % x: results -% check=1: the model can not be solved +% errorflag=1: the model can not be solved % % SPECIAL REQUIREMENTS % none -% Copyright © 2001-2021 Dynare Team +% Copyright © 2001-2022 Dynare Team % % This file is part of Dynare. % @@ -48,7 +49,7 @@ tolmin = tolx ; stpmx = 100 ; -check = 0 ; +errorflag = false ; fvec = feval(func,x,varargin{:}); fvec = fvec(j1); @@ -60,50 +61,50 @@ idCpx = ~isreal(fvec); if any(idInf) disp('SOLVE1: during the resolution of the non-linear system, the evaluation of the following equation(s) resulted in a non-finite number:') disp(j1(idInf)') - check = 1; + errorflag = true; return end if any(idNan) disp('SOLVE1: during the resolution of the non-linear system, the evaluation of the following equation(s) resulted in a nan:') disp(j1(idNan)') - check = 1; + errorflag = true; return end if any(idNan) disp('SOLVE1: during the resolution of the non-linear system, the evaluation of the following equation(s) resulted in a complex number:') disp(j1(idCpx)') - check = 1; + errorflag = true; return end +f = 0.5*(fvec'*fvec); -f = 0.5*(fvec'*fvec) ; - -if max(abs(fvec)) < tolf*tolf - return ; +if max(abs(fvec)) 0 + if lnsearchflag + errorflag = true; den = max([f;0.5*nn]) ; if max(abs(g).*max([abs(x(j2)') ones(1,nn)])')/den < tolmin if max(abs(x(j2)-xold(j2))./max([abs(x(j2)') ones(1,nn)])') < tolx @@ -149,13 +151,12 @@ for its = 1:maxit disp (x) return end - elseif max(abs(fvec)) < tolf return end end -check = 1; +errorflag = true; skipline() disp('SOLVE: maxit has been reached')