diff --git a/DynamicModel.cc b/DynamicModel.cc index e69244ee..a41e7b7a 100644 --- a/DynamicModel.cc +++ b/DynamicModel.cc @@ -2318,10 +2318,10 @@ DynamicModel::writeDynamicModel(ostream &DynamicOutput, bool use_dll, bool julia << " %" << endl << endl << jacobian_output.str() - << "end" << endl; + << endl // Initialize g2 matrix - DynamicOutput << "if nargout >= 3," << endl + << "if nargout >= 3," << endl << " %" << endl << " % Hessian matrix" << endl << " %" << endl @@ -2332,7 +2332,6 @@ DynamicModel::writeDynamicModel(ostream &DynamicOutput, bool use_dll, bool julia << " g2 = sparse(v2(:,1),v2(:,2),v2(:,3)," << nrows << "," << hessianColsNbr << ");" << endl; else // Either hessian is all zero, or we didn't compute it DynamicOutput << " g2 = sparse([],[],[]," << nrows << "," << hessianColsNbr << ");" << endl; - DynamicOutput << "end" << endl; // Initialize g3 matrix DynamicOutput << "if nargout >= 4," << endl @@ -2348,7 +2347,9 @@ DynamicModel::writeDynamicModel(ostream &DynamicOutput, bool use_dll, bool julia else // Either 3rd derivatives is all zero, or we didn't compute it DynamicOutput << " g3 = sparse([],[],[]," << nrows << "," << ncols << ");" << endl; - DynamicOutput << "end" << endl; + DynamicOutput << "end" << endl + << "end" << endl + << "end" << endl; } else if (output_type == oCDynamicModel) { @@ -2362,28 +2363,25 @@ DynamicModel::writeDynamicModel(ostream &DynamicOutput, bool use_dll, bool julia << " /* Jacobian */" << endl << " if (g1 == NULL)" << endl << " return;" << endl - << " else" << endl - << " {" << endl + << endl << jacobian_output.str() - << " }" << endl; + << endl; if (second_derivatives.size()) DynamicOutput << " /* Hessian for endogenous and exogenous variables */" << endl << " if (v2 == NULL)" << endl << " return;" << endl - << " else" << endl - << " {" << endl + << endl << hessian_output.str() - << " }" << endl; + << endl; if (third_derivatives.size()) DynamicOutput << " /* Third derivatives for endogenous and exogenous variables */" << endl << " if (v3 == NULL)" << endl << " return;" << endl - << " else" << endl - << " {" << endl + << endl << third_derivatives_output.str() - << " }" << endl; + << endl; DynamicOutput << "}" << endl << endl; } diff --git a/StaticModel.cc b/StaticModel.cc index 81b16761..92aa43f6 100644 --- a/StaticModel.cc +++ b/StaticModel.cc @@ -1392,7 +1392,6 @@ StaticModel::writeStaticModel(ostream &StaticOutput, bool use_dll, bool julia) c << " if ~isreal(g1)" << endl << " g1 = real(g1)+2*imag(g1);" << endl << " end" << endl - << "end" << endl << "if nargout >= 3," << endl << " %" << endl << " % Hessian matrix" << endl @@ -1405,7 +1404,7 @@ StaticModel::writeStaticModel(ostream &StaticOutput, bool use_dll, bool julia) c << " g2 = sparse(v2(:,1),v2(:,2),v2(:,3)," << equations.size() << "," << g2ncols << ");" << endl; else StaticOutput << " g2 = sparse([],[],[]," << equations.size() << "," << g2ncols << ");" << endl; - StaticOutput << "end" << endl; + // Initialize g3 matrix StaticOutput << "if nargout >= 4," << endl << " %" << endl @@ -1419,6 +1418,9 @@ StaticModel::writeStaticModel(ostream &StaticOutput, bool use_dll, bool julia) c << " g3 = sparse(v3(:,1),v3(:,2),v3(:,3)," << nrows << "," << ncols << ");" << endl; else // Either 3rd derivatives is all zero, or we didn't compute it StaticOutput << " g3 = sparse([],[],[]," << nrows << "," << ncols << ");" << endl; + StaticOutput << "end" << endl + << "end" << endl + << "end" << endl; } else if (output_type == oCStaticModel) { @@ -1432,27 +1434,24 @@ StaticModel::writeStaticModel(ostream &StaticOutput, bool use_dll, bool julia) c << " /* Jacobian */" << endl << " if (g1 == NULL)" << endl << " return;" << endl - << " else" << endl - << " {" << endl + << endl << jacobian_output.str() - << " }" << endl; + << endl; if (second_derivatives.size()) StaticOutput << " /* Hessian for endogenous and exogenous variables */" << endl << " if (v2 == NULL)" << endl << " return;" << endl - << " else" << endl - << " {" << endl + << endl << hessian_output.str() - << " }" << endl; + << endl; if (third_derivatives.size()) StaticOutput << " /* Third derivatives for endogenous and exogenous variables */" << endl - << " if (v3 == NULL)" << endl - << " return;" << endl - << " else" << endl - << " {" << endl - << third_derivatives_output.str() - << " }" << endl; + << " if (v3 == NULL)" << endl + << " return;" << endl + << endl + << third_derivatives_output.str() + << endl; } else {