1function []=display_problematic_vars_Jacobian(problemrow,problemcol,M_,x,type,caller_string) 2% []=display_problematic_vars_Jacobian(problemrow,problemcol,M_,ys,caller_string) 3% print the equation numbers and variables associated with problematic entries 4% of the Jacobian 5% 6% INPUTS 7% problemrow [vector] rows associated with problematic entries 8% problemcol [vector] columns associated with problematic entries 9% M_ [matlab structure] Definition of the model. 10% x [vector] point at which the Jacobian was evaluated 11% type [string] 'static' or 'dynamic' depending on the type of 12% Jacobian 13% caller_string [string] contains name of calling function for printing 14% 15% OUTPUTS 16% none. 17% 18 19% Copyright (C) 2014-2018 Dynare Team 20% 21% This file is part of Dynare. 22% 23% Dynare is free software: you can redistribute it and/or modify 24% it under the terms of the GNU General Public License as published by 25% the Free Software Foundation, either version 3 of the License, or 26% (at your option) any later version. 27% 28% Dynare is distributed in the hope that it will be useful, 29% but WITHOUT ANY WARRANTY; without even the implied warranty of 30% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 31% GNU General Public License for more details. 32% 33% You should have received a copy of the GNU General Public License 34% along with Dynare. If not, see <http://www.gnu.org/licenses/>. 35 36skipline(); 37if nargin<6 38 caller_string=''; 39end 40aux_eq_nbr=M_.eq_nbr-M_.orig_eq_nbr; 41if strcmp(type,'dynamic') 42 for ii=1:length(problemrow) 43 if problemcol(ii)>max(M_.lead_lag_incidence) 44 var_row=2; 45 var_index=problemcol(ii)-max(max(M_.lead_lag_incidence)); 46 else 47 [var_row,var_index]=find(M_.lead_lag_incidence==problemcol(ii)); 48 end 49 if var_row==2 50 type_string=''; 51 elseif var_row==1 52 type_string='lag of'; 53 elseif var_row==3 54 type_string='lead of'; 55 end 56 if problemcol(ii)<=max(max(M_.lead_lag_incidence)) && var_index<=M_.orig_endo_nbr 57 if problemrow(ii)<=aux_eq_nbr 58 eq_nbr = problemrow(ii); 59 fprintf('Derivative of Auxiliary Equation %d with respect to %s Variable %s (initial value of %s: %g) \n', ... 60 eq_nbr, type_string, M_.endo_names{var_index}, M_.endo_names{var_index}, x(var_index)); 61 else 62 eq_nbr = problemrow(ii)-aux_eq_nbr; 63 fprintf('Derivative of Equation %d with respect to %s Variable %s (initial value of %s: %g) \n', ... 64 eq_nbr, type_string, M_.endo_names{var_index}, M_.endo_names{var_index}, x(var_index)); 65 end 66 elseif problemcol(ii)<=max(max(M_.lead_lag_incidence)) && var_index>M_.orig_endo_nbr % auxiliary vars 67 if M_.aux_vars(1,problemcol(ii)-M_.orig_endo_nbr).type==6 %Ramsey Lagrange Multiplier 68 if problemrow(ii)<=aux_eq_nbr 69 eq_nbr = problemrow(ii); 70 fprintf('Derivative of Auxiliary Equation %d with respect to %s of Langrange multiplier of equation %s (initial value: %g) \n', ... 71 eq_nbr, type_string, M_.aux_vars(1,problemcol(ii)-M_.orig_endo_nbr).eq_nbr, x(problemcol(ii))); 72 else 73 eq_nbr = problemrow(ii)-aux_eq_nbr; 74 fprintf('Derivative of Equation %d with respect to %s of Langrange multiplier of equation %s (initial value: %g) \n', ... 75 eq_nbr, type_string, M_.aux_vars(1,problemcol(ii)-M_.orig_endo_nbr).eq_nbr, x(problemcol(ii))); 76 end 77 else 78 if problemrow(ii)<=aux_eq_nbr 79 eq_nbr = problemrow(ii); 80 orig_var_index = M_.aux_vars(1,var_index-M_.orig_endo_nbr).orig_index; 81 fprintf('Derivative of Auxiliary Equation %d with respect to %s Variable %s (initial value of %s: %g) \n', ... 82 eq_nbr, type_string, M_.endo_names{orig_var_index}, M_.endo_names{orig_var_index}, x(orig_var_index)); 83 else 84 eq_nbr = problemrow(ii)-aux_eq_nbr; 85 orig_var_index = M_.aux_vars(1,var_index-M_.orig_endo_nbr).orig_index; 86 fprintf('Derivative of Equation %d with respect to %s Variable %s (initial value of %s: %g) \n', ... 87 eq_nbr, type_string, M_.endo_names{orig_var_index}, M_.endo_names{orig_var_index}, x(orig_var_index)); 88 end 89 end 90 elseif problemcol(ii)>max(max(M_.lead_lag_incidence)) && var_index<=M_.exo_nbr 91 if problemrow(ii)<=aux_eq_nbr 92 eq_nbr = problemrow(ii); 93 fprintf('Derivative of Auxiliary Equation %d with respect to %s shock %s \n', ... 94 eq_nbr, type_string, M_.exo_names{var_index}); 95 else 96 eq_nbr = problemrow(ii)-aux_eq_nbr; 97 fprintf('Derivative of Equation %d with respect to %s shock %s \n', ... 98 eq_nbr, type_string, M_.exo_names{var_index}); 99 end 100 else 101 error('display_problematic_vars_Jacobian:: The error should not happen. Please contact the developers') 102 end 103 end 104 fprintf('\n%s The problem most often occurs, because a variable with\n', caller_string) 105 fprintf('%s exponent smaller than 1 has been initialized to 0. Taking the derivative\n', caller_string) 106 fprintf('%s and evaluating it at the steady state then results in a division by 0.\n', caller_string) 107 fprintf('%s If you are using model-local variables (# operator), check their values as well.\n', caller_string) 108elseif strcmp(type, 'static') 109 for ii=1:length(problemrow) 110 if problemcol(ii)<=M_.orig_endo_nbr 111 if problemrow(ii)<=aux_eq_nbr 112 eq_nbr = problemrow(ii); 113 fprintf('Derivative of Auxiliary Equation %d with respect to Variable %s (initial value of %s: %g) \n', ... 114 eq_nbr, M_.endo_names{problemcol(ii)}, M_.endo_names{problemcol(ii)}, x(problemcol(ii))); 115 else 116 eq_nbr = problemrow(ii)-aux_eq_nbr; 117 fprintf('Derivative of Equation %d with respect to Variable %s (initial value of %s: %g) \n', ... 118 eq_nbr, M_.endo_names{problemcol(ii)}, M_.endo_names{problemcol(ii)}, x(problemcol(ii))); 119 end 120 else %auxiliary vars 121 if M_.aux_vars(1,problemcol(ii)-M_.orig_endo_nbr).type ==6 %Ramsey Lagrange Multiplier 122 if problemrow(ii)<=aux_eq_nbr 123 eq_nbr = problemrow(ii); 124 fprintf('Derivative of Auxiliary Equation %d with respect to Lagrange multiplier of equation %d (initial value: %g) \n', ... 125 eq_nbr, M_.aux_vars(1,problemcol(ii)-M_.orig_endo_nbr).eq_nbr, x(problemcol(ii))); 126 else 127 eq_nbr = problemrow(ii)-aux_eq_nbr; 128 fprintf('Derivative of Equation %d with respect to Lagrange multiplier of equation %d (initial value: %g) \n', ... 129 eq_nbr, M_.aux_vars(1,problemcol(ii)-M_.orig_endo_nbr).eq_nbr, x(problemcol(ii))); 130 end 131 else 132 if problemrow(ii)<=aux_eq_nbr 133 eq_nbr = problemrow(ii); 134 orig_var_index = M_.aux_vars(1,problemcol(ii)-M_.orig_endo_nbr).orig_index; 135 fprintf('Derivative of Auxiliary Equation %d with respect to Variable %s (initial value of %s: %g) \n', ... 136 eq_nbr, M_.endo_names{orig_var_index}, M_.endo_names{orig_var_index}, x(problemcol(ii))); 137 else 138 eq_nbr = problemrow(ii)-aux_eq_nbr; 139 orig_var_index = M_.aux_vars(1,problemcol(ii)-M_.orig_endo_nbr).orig_index; 140 fprintf('Derivative of Equation %d with respect to Variable %s (initial value of %s: %g) \n', ... 141 eq_nbr, M_.endo_names{orig_var_index}, M_.endo_names{orig_var_index}, x(problemcol(ii))); 142 end 143 end 144 end 145 end 146 fprintf('\n%s The problem most often occurs, because a variable with\n', caller_string) 147 fprintf('%s exponent smaller than 1 has been initialized to 0. Taking the derivative\n', caller_string) 148 fprintf('%s and evaluating it at the steady state then results in a division by 0.\n', caller_string) 149 fprintf('%s If you are using model-local variables (# operator), check their values as well.\n', caller_string) 150else 151 error('Unknown Type') 152end