Commit fec9486f by sebastien

### Change to option solve_algo=4 of steady:

```Even when the Jacobian is very badly conditioned, continue to use a Newton step

git-svn-id: https://www.dynare.org/svn/dynare/trunk@2862 ac1d8469-bf42-47a9-8791-bf33cf982152```
parent 64361938
 ... ... @@ -61,7 +61,7 @@ function [x,info] = dynare_solve(func,x,jacobian_flag,varargin) end elseif options_.solve_algo == 1 nn = size(x,1); [x,info]=solve1(func,x,1:nn,1:nn,jacobian_flag,varargin{:}); [x,info]=solve1(func,x,1:nn,1:nn,jacobian_flag,1,varargin{:}); elseif options_.solve_algo == 2 || options_.solve_algo == 4 nn = size(x,1) ; tolf = options_.solve_tolf ; ... ... @@ -101,27 +101,22 @@ function [x,info] = dynare_solve(func,x,jacobian_flag,varargin) if options_.debug disp(['DYNARE_SOLVE (solve_algo=2|4): number of blocks = ' num2str(length(r))]); end % Activate bad conditioning flag for solve_algo = 2, but not for solve_algo = 4 bad_cond_flag = (options_.solve_algo == 2); 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 if options_.solve_algo == 2 [x,info]=solve1(func,x,j1(r(i):r(i+1)-1),j2(r(i):r(i+1)-1),jacobian_flag,varargin{:}); else % solve_algo=4 [x,info]=solve2(func,x,j1(r(i):r(i+1)-1),j2(r(i):r(i+1)-1),jacobian_flag,varargin{:}); end [x,info]=solve1(func,x,j1(r(i):r(i+1)-1),j2(r(i):r(i+1)-1),jacobian_flag, bad_cond_flag, varargin{:}); if info return end end fvec = feval(func,x,varargin{:}); if max(abs(fvec)) > tolf if options_.solve_algo == 2 [x,info]=solve1(func,x,1:nn,1:nn,jacobian_flag,varargin{:}); else % solve_algo=4 [x,info]=solve2(func,x,1:nn,1:nn,jacobian_flag,varargin{:}); end [x,info]=solve1(func,x,1:nn,1:nn,jacobian_flag, bad_cond_flag, varargin{:}); end elseif options_.solve_algo == 3 if jacobian_flag ... ...
 function [x,check] = solve1(func,x,j1,j2,jacobian_flag,varargin) % function [x,check] = solve1(func,x,j1,j2,jacobian_flag,varargin) function [x,check] = solve1(func,x,j1,j2,jacobian_flag,bad_cond_flag,varargin) % function [x,check] = solve1(func,x,j1,j2,jacobian_flag,bad_cond_flag,varargin) % Solves systems of non linear equations of several variables % % INPUTS ... ... @@ -9,7 +9,9 @@ function [x,check] = solve1(func,x,j1,j2,jacobian_flag,varargin) % j2: unknown variables index % jacobian_flag=1: jacobian given by the 'func' function % jacobian_flag=0: jacobian obtained numerically % varargin: list of arguments following jacobian_flag % bad_cond_flag=1: when Jacobian is badly conditionned, use an % alternative formula to Newton step % varargin: list of arguments following bad_cond_flag % % OUTPUTS % x: results ... ... @@ -18,7 +20,7 @@ function [x,check] = solve1(func,x,j1,j2,jacobian_flag,varargin) % SPECIAL REQUIREMENTS % none % Copyright (C) 2001-2008 Dynare Team % Copyright (C) 2001-2009 Dynare Team % % This file is part of Dynare. % ... ... @@ -113,8 +115,7 @@ function [x,check] = solve1(func,x,j1,j2,jacobian_flag,varargin) fvec = q'*fvec; p = e*[-r(1:end-n,1:end-n)\fvec(1:end-n);zeros(n,1)]; end % elseif cond(fjac) > 10*sqrt(eps) elseif cond(fjac) > 1/sqrt(eps) elseif bad_cond_flag && cond(fjac) > 1/sqrt(eps) fjac2=fjac'*fjac; p=-(fjac2+sqrt(nn*eps)*max(sum(abs(fjac2)))*eye(nn))\(fjac'*fvec); else ... ...