Commit 3fe5a728 authored by Sébastien Villemot's avatar Sébastien Villemot
Browse files

Remove bad_cond_flag argument from solve1.

This flag was not grounded on any solid theoretical foundation.

This commit actually makes solve_algo=2 to be exactly the same than solve_algo=4.
parent 0bcc628b
......@@ -109,7 +109,7 @@ function [dr,info] = dyn_risky_steadystate_solver(ys0,M, ...
x0 = ys0(pm.v_p);
n = length(x0);
[x, info] = solve1(@risky_residuals_ds,x0,1:n,1:n,0,1, options.gstep, ...
[x, info] = solve1(@risky_residuals_ds,x0,1:n,1:n,0,options.gstep, ...
options.solve_tolf,options.solve_tolx, ...
options.steady.maxit,options.debug,pm,M,dr, ...
options,oo);
......@@ -124,7 +124,7 @@ function [dr,info] = dyn_risky_steadystate_solver(ys0,M, ...
pm = model_structure(M,options);
end
[ys, info] = solve1(func,ys0,1:endo_nbr,1:endo_nbr,0,1, options.gstep, ...
[ys, info] = solve1(func,ys0,1:endo_nbr,1:endo_nbr,0,options.gstep, ...
options.solve_tolf,options.solve_tolx, ...
options.steady.maxit,options.debug,pm,M,dr,options,oo);
% [ys, info] = csolve(func,ys0,[],1e-10,100,M,dr,options,oo);
......
......@@ -120,7 +120,7 @@ if options_.solve_algo == 0
info = 1;
end
elseif options_.solve_algo == 1
[x,info]=solve1(func,x,1:nn,1:nn,jacobian_flag,1,options_.gstep, ...
[x,info]=solve1(func,x,1:nn,1:nn,jacobian_flag,options_.gstep, ...
tolf,options_.solve_tolx, ...
options_.steady.maxit,options_.debug,varargin{:});
elseif options_.solve_algo == 2 || options_.solve_algo == 4
......@@ -140,15 +140,12 @@ elseif options_.solve_algo == 2 || options_.solve_algo == 4
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
[x,info]=solve1(func,x,j1(r(i):r(i+1)-1),j2(r(i):r(i+1)-1),jacobian_flag, ...
bad_cond_flag, options_.gstep, ...
options_.gstep, ...
tolf,options_.solve_tolx, ...
options_.steady.maxit,options_.debug,varargin{:});
if info
......@@ -157,7 +154,7 @@ elseif options_.solve_algo == 2 || options_.solve_algo == 4
end
fvec = feval(func,x,varargin{:});
if max(abs(fvec)) > tolf
[x,info]=solve1(func,x,1:nn,1:nn,jacobian_flag, bad_cond_flag, ...
[x,info]=solve1(func,x,1:nn,1:nn,jacobian_flag, ...
options_.gstep, tolf,options_.solve_tolx, ...
options_.steady.maxit,options_.debug,varargin{:});
end
......
......@@ -41,7 +41,7 @@ function sim1_purely_backward()
yb1 = yb(iyb);
tmp = solve1(model_dynamic, [yb1; yb], 1:M_.endo_nbr, nyb+1:nyb+ ...
M_.endo_nbr, 1, 1, options_.gstep, ...
M_.endo_nbr, 1, options_.gstep, ...
options_.solve_tolf,options_.solve_tolx, ...
options_.simul.maxit,options_.debug,oo_.exo_simul, ...
M_.params, oo_.steady_state, it);
......
......@@ -34,7 +34,7 @@ function sim1_purely_forward()
yf1 = yf(iyf);
tmp = solve1(model_dynamic, [yf; yf1], 1:M_.endo_nbr, 1:M_.endo_nbr, ...
1, 1, options_.gstep, options_.solve_tolf, ...
1, options_.gstep, options_.solve_tolf, ...
options_.solve_tolx, options_.simul.maxit, ...
options_.debug,oo_.exo_simul, M_.params, oo_.steady_state, ...
it);
......
......@@ -105,7 +105,7 @@ DynareOutput.endo_simul(:,1) = DynareOutput.steady_state;
for it = 2:sample_size+1
y(jdx) = DynareOutput.endo_simul(:,it-1); % A good guess for the initial conditions is the previous values for the endogenous variables.
y(hdx) = y(jdx(iy1)); % Set lagged variables.
y(jdx) = solve1(model_dynamic, y, idx, jdx, 1, 1, DynareOptions.gstep, ...
y(jdx) = solve1(model_dynamic, y, idx, jdx, 1, DynareOptions.gstep, ...
DynareOptions.solve_tolf,DynareOptions.solve_tolx, ...
DynareOptions.simul.maxit,DynareOptions.debug, ...
DynareOutput.exo_simul, DynareModel.params, ...
......
function [x,check] = solve1(func,x,j1,j2,jacobian_flag,bad_cond_flag,gstep,tolf,tolx,maxit,debug,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,gstep,tolf,tolx,maxit,debug,varargin)
% Solves systems of non linear equations of several variables
%
% INPUTS
......@@ -9,15 +8,13 @@ function [x,check] = solve1(func,x,j1,j2,jacobian_flag,bad_cond_flag,gstep,tolf,
% j2: unknown variables index
% jacobian_flag=1: jacobian given by the 'func' function
% jacobian_flag=0: jacobian obtained numerically
% bad_cond_flag=1: when Jacobian is badly conditionned, use an
% alternative formula to Newton step
% gstep increment multiplier in numercial derivative
% computation
% tolf tolerance for residuals
% tolx tolerance for solution variation
% maxit maximum number of iterations
% debug debug flag
% varargin: list of arguments following bad_cond_flag
% varargin: list of extra arguments to the function
%
% OUTPUTS
% x: results
......@@ -26,7 +23,7 @@ function [x,check] = solve1(func,x,j1,j2,jacobian_flag,bad_cond_flag,gstep,tolf,
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2001-2012 Dynare Team
% Copyright (C) 2001-2014 Dynare Team
%
% This file is part of Dynare.
%
......@@ -95,7 +92,7 @@ for its = 1:maxit
if debug
disp(['cond(fjac) ' num2str(cond(fjac))])
end
if bad_cond_flag && rcond(fjac) < sqrt(eps)
if rcond(fjac) < sqrt(eps)
fjac2=fjac'*fjac;
p=-(fjac2+1e6*sqrt(nn*eps)*max(sum(abs(fjac2)))*eye(nn))\(fjac'*fvec);
else
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment