diff --git a/matlab/perfect-foresight-models/sim1.m b/matlab/perfect-foresight-models/sim1.m index 05ef5b186732ee19a565b9890b99c8c9771dd70d..bb93691ed505d02d164c39d31ba68b624577722a 100644 --- a/matlab/perfect-foresight-models/sim1.m +++ b/matlab/perfect-foresight-models/sim1.m @@ -184,7 +184,33 @@ if stop if verbose skipline() disp(sprintf('Total time of simulation: %s.', num2str(etime(clock,h1)))) - disp('Simulation terminated with NaN or Inf in the residuals or endogenous variables.') + 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 disp('There is most likely something wrong with your model. Try model_diagnostics or another simulation method.') printline(105) end