Skip to content
Snippets Groups Projects
Commit 234aaacf authored by Marco Ratto's avatar Marco Ratto
Browse files

factorized display of critical values.

parent 76097a79
No related branches found
No related tags found
1 merge request!1419factorized display of critical values.
......@@ -165,6 +165,11 @@ for iter = 1:options.simul.maxit
dy = -lin_solve( A, res, verbose );
end
end
if (any(~isreal(dy)) || any(isnan(dy)) || any(isinf(dy)) ,
if verbose
display_critical_variables(reshape(dy,[ny periods])', M);
end
end
Y(i_upd) = Y(i_upd) + dy;
end
......@@ -184,33 +189,12 @@ if stop
if verbose
skipline()
disp(sprintf('Total time of simulation: %s.', num2str(etime(clock,h1))))
dyy=reshape(dy,[size(endogenousvariables,1) periods])';
if ~isreal(res) || ~isreal(Y)
disp('Simulation terminated with imaginary parts in the residuals or endogenous variables.')
if any(~isreal(dy))
indx = find(any(~isreal(dyy)));
endo_names=cellstr(M.endo_names(indx,:));
disp('Newton algorithm provided complex number for variables:')
fprintf('%s, ', endo_names{:});
skipline()
end
else
disp('Simulation terminated with NaN or Inf in the residuals or endogenous variables.')
if any(isnan(dy))
indx = find(any(isnan(dyy)));
endo_names=cellstr(M.endo_names(indx,:));
disp('Newton algorithm provided NaN for variables:')
fprintf('%s, ',endo_names{:});
skipline()
end
if any(isinf(dy))
indx = find(any(isinf(dyy)));
endo_names=cellstr(M.endo_names(indx,:));
disp('Newton algorithm diverged (Inf) for variables:')
fprintf('%s, ',endo_names{:});
skipline()
end
end
display_critical_variables(reshape(dy,[ny periods])', M);
disp('There is most likely something wrong with your model. Try model_diagnostics or another simulation method.')
printline(105)
end
......@@ -323,3 +307,29 @@ function [ x, flag, relres ] = lin_solve_robust( A, b , verbose)
if flag ~= 0 && verbose
fprintf( 'WARNING : Failed to find a solution to the linear system\n' );
end
function display_critical_variables(dyy, M)
if any(isnan(dyy))
indx = find(any(isnan(dyy)));
endo_names=cellstr(M.endo_names(indx,:));
disp('Last iteration provided NaN for the following variables:')
fprintf('%s, ',endo_names{:}),
fprintf('\n'),
end
if any(isinf(dyy))
indx = find(any(isinf(dyy)));
endo_names=cellstr(M.endo_names(indx,:));
disp('Last iteration diverged (Inf) for the following variables:')
fprintf('%s, ',endo_names{:}),
fprintf('\n'),
end
if any(~isreal(dyy))
indx = find(any(~isreal(dyy)));
endo_names=cellstr(M.endo_names(indx,:));
disp('Last iteration provided complex number for the following variables:')
fprintf('%s, ',endo_names{:}),
fprintf('\n'),
end
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment