Skip to content
Snippets Groups Projects
Verified Commit d3ddb7b9 authored by Sébastien Villemot's avatar Sébastien Villemot
Browse files

sim1.m: include linear system resolution in displayed iteration time

By the way, rename “stop” variable to “converged” for clarity.
parent 9d21b16e
No related branches found
No related tags found
No related merge requests found
......@@ -53,8 +53,6 @@ end
y = reshape(endogenousvariables(:, M_.maximum_lag+(1:periods)), ny*periods, 1);
stop = false;
if verbose
skipline()
printline(56)
......@@ -63,8 +61,10 @@ if verbose
end
h1 = clock;
iter = 1;
converged = false;
for iter = 1:options_.simul.maxit
while ~(converged || iter > options_.simul.maxit)
h2 = clock;
[res, A] = perfect_foresight_problem(y, y0, yT, exogenousvariables, M_.params, steadystate, periods, M_, options_);
......@@ -118,24 +118,25 @@ for iter = 1:options_.simul.maxit
end
skipline()
end
if verbose
fprintf('Iter: %d,\t err. = %g,\t time = %g\n', iter, err, etime(clock,h2));
end
if err < options_.dynatol.f
stop = true;
break
end
if options_.simul.robust_lin_solve
dy = -lin_solve_robust(A, res, verbose, options_);
converged = true;
else
dy = -lin_solve(A, res, verbose, options_);
end
if any(isnan(dy)) || any(isinf(dy))
if verbose
display_critical_variables(reshape(dy,[ny periods])', M_, options_.noprint);
if options_.simul.robust_lin_solve
dy = -lin_solve_robust(A, res, verbose, options_);
else
dy = -lin_solve(A, res, verbose, options_);
end
if any(isnan(dy)) || any(isinf(dy))
if verbose
display_critical_variables(reshape(dy,[ny periods])', M_, options_.noprint);
end
end
y = y + dy;
end
y = y + dy;
if verbose
fprintf('Iter: %d,\t err. = %g,\t time = %g\n', iter, err, etime(clock,h2));
end
iter = iter + 1;
end
endogenousvariables(:, M_.maximum_lag+(1:periods)) = reshape(y, ny, periods);
......@@ -145,7 +146,7 @@ if options_.endogenous_terminal_period
err = evaluate_max_dynamic_residual(str2func([M_.fname,'.sparse.dynamic_resid']), endogenousvariables, exogenousvariables, M_.params, steadystate, periods, M_.maximum_lag);
end
if stop
if converged
% initial or terminal observations may contain
% harmless NaN or Inf. We test only values computed above
if any(any(isnan(y))) || any(any(isinf(y)))
......@@ -166,7 +167,7 @@ if stop
end
success = true; % Convergency obtained.
end
elseif ~stop
else
if verbose
skipline();
fprintf('Total time of simulation: %g.\n', etime(clock,h1))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment