diff --git a/matlab/dynare_solve.m b/matlab/dynare_solve.m index c48ea368e..f00b8eea9 100644 --- a/matlab/dynare_solve.m +++ b/matlab/dynare_solve.m @@ -113,8 +113,16 @@ if options.solve_algo == 0 end; end - if exitval > 0 + if exitval == 1 info = 0; + elseif exitval > 1 + M=evalin('base','M_'); %get variable names from workspace + resid = evaluate_static_model(x,varargin{:},M,options); + if max(abs(resid)) > 1e-6 + info = 1; + else + info = 0; + end else info = 1; end diff --git a/matlab/solve1.m b/matlab/solve1.m index 937909d09..5d5241fce 100644 --- a/matlab/solve1.m +++ b/matlab/solve1.m @@ -118,7 +118,13 @@ for its = 1:maxit if check > 0 den = max([f;0.5*nn]) ; if max(abs(g).*max([abs(x(j2)') ones(1,nn)])')/den < tolmin - return + if max(abs(x(j2)-xold(j2))./max([abs(x(j2)') ones(1,nn)])') < tolx + disp (' ') + disp (['SOLVE: Iteration ' num2str(its)]) + disp (['Convergence on dX.']) + disp (x) + return + end else disp (' ') disp (['SOLVE: Iteration ' num2str(its)]) @@ -127,13 +133,6 @@ for its = 1:maxit return end - if max(abs(x(j2)-xold(j2))./max([abs(x(j2)') ones(1,nn)])') < tolx - disp (' ') - disp (['SOLVE: Iteration ' num2str(its)]) - disp (['Convergence on dX.']) - disp (x) - return - end elseif max(abs(fvec)) < tolf return end diff --git a/matlab/trust_region.m b/matlab/trust_region.m index 2de813967..cda54684b 100644 --- a/matlab/trust_region.m +++ b/matlab/trust_region.m @@ -1,4 +1,4 @@ -function [x,check] = trust_region(fcn,x0,j1,j2,jacobian_flag,gstep,tolf,tolx,maxiter,debug,varargin) +function [x,check,info] = trust_region(fcn,x0,j1,j2,jacobian_flag,gstep,tolf,tolx,maxiter,debug,varargin) % Solves systems of non linear equations of several variables, using a % trust-region method. % @@ -20,12 +20,12 @@ function [x,check] = trust_region(fcn,x0,j1,j2,jacobian_flag,gstep,tolf,tolx,max % OUTPUTS % x: results % check=1: the model can not be solved -% +% info: detailed exitcode % SPECIAL REQUIREMENTS % none % Copyright (C) 2008-2012 VZLU Prague, a.s. -% Copyright (C) 2014 Dynare Team +% Copyright (C) 2016 Dynare Team % % This file is part of Dynare. % @@ -82,7 +82,6 @@ while (niter < maxiter && ~info) xdh(j2(j)) = xdh(j2(j))+dh(j) ; t = fcn(xdh,varargin{:}); fjac(:,j) = (t(j1) - fvec)./dh(j) ; - g(j) = fvec'*fjac(:,j) ; end end