Fix trust region exit criterion
In trust_region.m
we have a problem with trying to encode three pieces of information in a binary variable check
The problem is error code -3 (Trust region became uselessly small). c01352ea tried to prevent the solver from accepting error code -3 as a solved steady state. But this breaks the loop in dynare_solve.m
:
for i=length(r)-1:-1:1
if options.debug
disp(['DYNARE_SOLVE (solve_algo=2|4): solving block ' num2str(i) ', of size ' num2str(r(i+1)-r(i)) ]);
end
[x,info]=solver(func,x,j1(r(i):r(i+1)-1),j2(r(i):r(i+1)-1),jacobian_flag, ...
options.gstep, ...
tolf,options.solve_tolx, ...
options.steady.maxit,options.debug,varargin{:});
if info
return
end
end
which relies on being able to continue with the loop when the code internally was -3 (as ~(-3)=0), i.e. we discard the information that -3 is a problem. But further below we have the final check
if max(abs(fvec)) > tolf
[x,info]=solver(func,x,1:nn,1:nn,jacobian_flag, ...
options.gstep, tolf,options.solve_tolx, ...
options.steady.maxit,options.debug,varargin{:});
end
Here, we would need to know whether a 0 in info comes from info = (1) (everything fine) vs. info=(-3) (still a problem after the last iteration).
My proposed solution would be to augment both trust_region.m
and solve1.m
with a third output argument exitflag
that encodes the full integer error code. That way we would only need to check for this argument in the final check of dynare_solve.m