From 14576662213f68f55842eb9b86a9c4b423ce63eb Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Mon, 16 Nov 2015 11:11:58 +0100 Subject: [PATCH 1/4] Only accept steady state when fsolve retuns with normal return code 1 Otherwise, termination due to tolerance criteria will be accepted as correct steady state --- matlab/dynare_solve.m | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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 From 300ebd02b07458adadcba8c5ceb872a453971c01 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Sat, 12 Mar 2016 19:43:08 +0100 Subject: [PATCH 2/4] solve1: Move condition that could never be reached into if-clause --- matlab/solve1.m | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) 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 From 9c8da869f72c6c0c9179db8562b46b10393f41c7 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Sat, 12 Mar 2016 19:43:41 +0100 Subject: [PATCH 3/4] Delete redundant computation from trust_region.m --- matlab/trust_region.m | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/matlab/trust_region.m b/matlab/trust_region.m index 2de813967..61e4478ac 100644 --- a/matlab/trust_region.m +++ b/matlab/trust_region.m @@ -25,7 +25,7 @@ function [x,check] = trust_region(fcn,x0,j1,j2,jacobian_flag,gstep,tolf,tolx,max % 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 From 5d8bc7188cd5214b87a4a79fe36b2a7af5a517d7 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Sat, 12 Mar 2016 19:48:05 +0100 Subject: [PATCH 4/4] Allow detailed exitcode as output of trust_region.m --- matlab/trust_region.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/matlab/trust_region.m b/matlab/trust_region.m index 61e4478ac..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,7 +20,7 @@ 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