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
No related merge requests found
...@@ -165,6 +165,11 @@ for iter = 1:options.simul.maxit ...@@ -165,6 +165,11 @@ for iter = 1:options.simul.maxit
dy = -lin_solve( A, res, verbose ); dy = -lin_solve( A, res, verbose );
end end
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; Y(i_upd) = Y(i_upd) + dy;
end end
...@@ -184,33 +189,12 @@ if stop ...@@ -184,33 +189,12 @@ if stop
if verbose if verbose
skipline() skipline()
disp(sprintf('Total time of simulation: %s.', num2str(etime(clock,h1)))) disp(sprintf('Total time of simulation: %s.', num2str(etime(clock,h1))))
dyy=reshape(dy,[size(endogenousvariables,1) periods])';
if ~isreal(res) || ~isreal(Y) if ~isreal(res) || ~isreal(Y)
disp('Simulation terminated with imaginary parts in the residuals or endogenous variables.') 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 else
disp('Simulation terminated with NaN or Inf in the residuals or endogenous variables.') 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 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.') disp('There is most likely something wrong with your model. Try model_diagnostics or another simulation method.')
printline(105) printline(105)
end end
...@@ -323,3 +307,29 @@ function [ x, flag, relres ] = lin_solve_robust( A, b , verbose) ...@@ -323,3 +307,29 @@ function [ x, flag, relres ] = lin_solve_robust( A, b , verbose)
if flag ~= 0 && verbose if flag ~= 0 && verbose
fprintf( 'WARNING : Failed to find a solution to the linear system\n' ); fprintf( 'WARNING : Failed to find a solution to the linear system\n' );
end 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