solve_{one_boundary,two_boundaries}: convert some input arguments to logical type

time-shift
Sébastien Villemot 2020-05-25 16:58:11 +02:00
parent 6f0196be7f
commit 2015b79279
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
3 changed files with 25 additions and 30 deletions

View File

@ -37,9 +37,9 @@ if options.block && ~options.bytecode
else else
n = length(M.block_structure_stat.block(b).variable); n = length(M.block_structure_stat.block(b).variable);
[ss, check] = solve_one_boundary([M.fname '.block.static_' int2str(b)], ss, exo, ... [ss, check] = solve_one_boundary([M.fname '.block.static_' int2str(b)], ss, exo, ...
params, [], M.block_structure_stat.block(b).variable, n, 1, 0, b, 0, options.simul.maxit, ... params, [], M.block_structure_stat.block(b).variable, n, 1, false, b, 0, options.simul.maxit, ...
options.solve_tolf, ... options.solve_tolf, ...
options.slowc, 0, options.solve_algo, 1, 0, 0,M,options); options.slowc, 0, options.solve_algo, true, false, false, M, options);
if check if check
info = 1; info = 1;
return return

View File

@ -1,5 +1,5 @@
function [y, info] = solve_one_boundary(fname, y, x, params, steady_state, ... function [y, info] = solve_one_boundary(fname, y, x, params, steady_state, ...
y_index_eq, nze, periods, is_linear, Block_Num, y_kmin, maxit_, solve_tolf, lambda, cutoff, stack_solve_algo, forward_backward, is_dynamic, verbose, M, options, oo) y_index_eq, nze, periods, is_linear, Block_Num, y_kmin, maxit_, solve_tolf, lambda, cutoff, stack_solve_algo, is_forward, is_dynamic, verbose, M, options, oo)
% Computes the deterministic simulation of a block of equation containing % Computes the deterministic simulation of a block of equation containing
% lead or lag variables % lead or lag variables
% %
@ -15,8 +15,7 @@ function [y, info] = solve_one_boundary(fname, y, x, params, steady_state, ...
% nze [integer] number of non-zero elements in the % nze [integer] number of non-zero elements in the
% jacobian matrix % jacobian matrix
% periods [integer] number of simulation periods % periods [integer] number of simulation periods
% is_linear [integer] if is_linear=1 the block is linear % is_linear [logical] whether the block is linear
% if is_linear=0 the block is not linear
% Block_Num [integer] block number % Block_Num [integer] block number
% y_kmin [integer] maximum number of lag in the model % y_kmin [integer] maximum number of lag in the model
% maxit_ [integer] maximum number of iteration in Newton % maxit_ [integer] maximum number of iteration in Newton
@ -31,18 +30,15 @@ function [y, info] = solve_one_boundary(fname, y, x, params, steady_state, ...
% - 2 GMRES % - 2 GMRES
% - 3 BicGStab % - 3 BicGStab
% - 4 Optimal path length % - 4 Optimal path length
% forward_backward [integer] The block has to be solve forward % is_forward [logical] Whether the block has to be solved forward
% (1) or backward (0) % If false, the block is solved backward
% is_dynamic [integer] (1) The block belong to the dynamic % is_dynamic [logical] If true, the block belongs to the dynamic file
% file and the oo_.deterministic_simulation field has to be uptated % file and the oo_.deterministic_simulation field has to be uptated
% (0) The block belong to the static % If false, the block belongs to the static
% file and th oo_.deteerminstic % file and the oo_.detereministic_simulation
% field remains unchanged % field remains unchanged
% verbose [integer] (0) iterations are not printed % verbose [logical] Whether iterations are to be printed
% (1) iterations are printed %
% indirect_call [integer] (0) direct call to the fname
% (1) indirect call via the
% local_fname wrapper
% OUTPUTS % OUTPUTS
% y [matrix] All endogenous variables of the model % y [matrix] All endogenous variables of the model
% info [integer] >=0 no error % info [integer] >=0 no error
@ -55,7 +51,7 @@ function [y, info] = solve_one_boundary(fname, y, x, params, steady_state, ...
% none. % none.
% %
% Copyright (C) 1996-2018 Dynare Team % Copyright (C) 1996-2020 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
@ -80,7 +76,7 @@ correcting_factor=0.01;
ilu_setup.droptol=1e-10; ilu_setup.droptol=1e-10;
max_resa=1e100; max_resa=1e100;
reduced = 0; reduced = 0;
if forward_backward if is_forward
incr = 1; incr = 1;
start = y_kmin+1; start = y_kmin+1;
finish = periods+y_kmin; finish = periods+y_kmin;
@ -105,7 +101,7 @@ for it_=start:incr:finish
else else
max_res=max(max(abs(r))); max_res=max(max(abs(r)));
end end
if verbose==1 if verbose
disp(['iteration : ' int2str(iter+1) ' => ' num2str(max_res) ' time = ' int2str(it_)]) disp(['iteration : ' int2str(iter+1) ' => ' num2str(max_res) ' time = ' int2str(it_)])
if is_dynamic if is_dynamic
disp([M.endo_names{y_index_eq} num2str([y(it_,y_index_eq)' r g1])]) disp([M.endo_names{y_index_eq} num2str([y(it_,y_index_eq)' r g1])])
@ -230,7 +226,7 @@ for it_=start:incr:finish
info = -Block_Num*10; info = -Block_Num*10;
end end
elseif (~is_dynamic && options.solve_algo==2) || (is_dynamic && stack_solve_algo==4) elseif (~is_dynamic && options.solve_algo==2) || (is_dynamic && stack_solve_algo==4)
if verbose==1 && ~is_dynamic if verbose && ~is_dynamic
disp('steady: LU + lnsrch1') disp('steady: LU + lnsrch1')
end end
lambda=1; lambda=1;
@ -260,7 +256,7 @@ for it_=start:incr:finish
y = ya'; y = ya';
end end
elseif ~is_dynamic && options.solve_algo==3 elseif ~is_dynamic && options.solve_algo==3
if verbose==1 if verbose
disp('steady: csolve') disp('steady: csolve')
end end
[yn,info] = csolve(@local_fname, y(y_index_eq),@ ... [yn,info] = csolve(@local_fname, y(y_index_eq),@ ...
@ -268,7 +264,7 @@ for it_=start:incr:finish
dx = ya - yn; dx = ya - yn;
y(y_index_eq) = yn; y(y_index_eq) = yn;
elseif (stack_solve_algo==1 && is_dynamic) || (stack_solve_algo==0 && is_dynamic) || (~is_dynamic && (options.solve_algo==1 || options.solve_algo==6)) elseif (stack_solve_algo==1 && is_dynamic) || (stack_solve_algo==0 && is_dynamic) || (~is_dynamic && (options.solve_algo==1 || options.solve_algo==6))
if verbose==1 && ~is_dynamic if verbose && ~is_dynamic
disp('steady: Sparse LU ') disp('steady: Sparse LU ')
end end
dx = g1\r; dx = g1\r;
@ -280,7 +276,7 @@ for it_=start:incr:finish
end end
elseif (stack_solve_algo==2 && is_dynamic) || (options.solve_algo==7 && ~is_dynamic) elseif (stack_solve_algo==2 && is_dynamic) || (options.solve_algo==7 && ~is_dynamic)
flag1=1; flag1=1;
if verbose == 1 && ~is_dynamic if verbose && ~is_dynamic
disp('steady: GMRES ') disp('steady: GMRES ')
end end
while flag1>0 while flag1>0
@ -309,7 +305,7 @@ for it_=start:incr:finish
end end
elseif (stack_solve_algo==3 && is_dynamic) || (options.solve_algo==8 && ~is_dynamic) elseif (stack_solve_algo==3 && is_dynamic) || (options.solve_algo==8 && ~is_dynamic)
flag1=1; flag1=1;
if verbose == 1 && ~is_dynamic if verbose && ~is_dynamic
disp('steady: BiCGStab') disp('steady: BiCGStab')
end end
while flag1>0 while flag1>0
@ -377,7 +373,7 @@ for it_=start:incr:finish
fprintf('Error in simul: Convergence not achieved in block %d, at time %d, after %d iterations.\n Increase "options_.simul.maxit" or set "cutoff=0" in model options.\n',Block_Num, it_,iter); fprintf('Error in simul: Convergence not achieved in block %d, at time %d, after %d iterations.\n Increase "options_.simul.maxit" or set "cutoff=0" in model options.\n',Block_Num, it_,iter);
end end
end end
if(is_dynamic) if is_dynamic
oo_.deterministic_simulation.status = 0; oo_.deterministic_simulation.status = 0;
oo_.deterministic_simulation.error = max_res; oo_.deterministic_simulation.error = max_res;
oo_.deterministic_simulation.iterations = iter; oo_.deterministic_simulation.iterations = iter;

View File

@ -16,8 +16,7 @@ function [y, oo]= solve_two_boundaries(fname, y, x, params, steady_state, y_inde
% periods [integer] number of simulation periods % periods [integer] number of simulation periods
% y_kmin_l [integer] maximum number of lag in the block % y_kmin_l [integer] maximum number of lag in the block
% y_kmax_l [integer] maximum number of lead in the block % y_kmax_l [integer] maximum number of lead in the block
% is_linear [integer] if is_linear=1 the block is linear % is_linear [logical] Whether the block is linear
% if is_linear=0 the block is not linear
% Block_Num [integer] block number % Block_Num [integer] block number
% y_kmin [integer] maximum number of lag in the model % y_kmin [integer] maximum number of lag in the model
% maxit_ [integer] maximum number of iteration in Newton % maxit_ [integer] maximum number of iteration in Newton
@ -46,7 +45,7 @@ function [y, oo]= solve_two_boundaries(fname, y, x, params, steady_state, y_inde
% none. % none.
% %
% Copyright (C) 1996-2018 Dynare Team % Copyright (C) 1996-2020 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
@ -95,7 +94,7 @@ while ~(cvg==1 || iter>maxit_)
end end
if ~isreal(max_res) || isnan(max_res) if ~isreal(max_res) || isnan(max_res)
cvg = 0; cvg = 0;
elseif(is_linear && iter>0) elseif is_linear && iter>0
cvg = 1; cvg = 1;
else else
cvg=(max_res<solve_tolf); cvg=(max_res<solve_tolf);