diff --git a/preprocessor/DynamicModel.cc b/preprocessor/DynamicModel.cc index 5acdf8718..4df16e6c8 100644 --- a/preprocessor/DynamicModel.cc +++ b/preprocessor/DynamicModel.cc @@ -2788,11 +2788,12 @@ DynamicModel::writeParamsDerivativesFile(const string &basename) const paramsDerivsFile << "if nargout >= 3" << endl; // Write parameter second derivatives (only if nargout >= 3) - paramsDerivsFile << "rpp = zeros(" << equation_number() << ", " << symbol_table.param_nbr() << ", " - << symbol_table.param_nbr() << ");" << endl; + paramsDerivsFile << "rpp = zeros(" << residuals_params_second_derivatives.size() + << ",4);" << endl; + int i = 1; for (second_derivatives_type::const_iterator it = residuals_params_second_derivatives.begin(); - it != residuals_params_second_derivatives.end(); it++) + it != residuals_params_second_derivatives.end(); ++it, i++) { int eq = it->first.first; int param1 = it->first.second.first; @@ -2802,17 +2803,21 @@ DynamicModel::writeParamsDerivativesFile(const string &basename) const int param1_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param1)) + 1; int param2_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param2)) + 1; - paramsDerivsFile << "rpp(" << eq+1 << ", " << param1_col << ", " << param2_col << ") = "; + paramsDerivsFile << "rpp(" << i << ",1)=" << eq+1 << ";" << endl + << "rpp(" << i << ",2)=" << param1_col << ";" << endl + << "rpp(" << i << ",3)=" << param2_col << ";" << endl + << "rpp(" << i << ",4)="; d2->writeOutput(paramsDerivsFile, oMatlabDynamicModel, params_derivs_temporary_terms); paramsDerivsFile << ";" << endl; } // Write jacobian second derivatives (only if nargout >= 3) - paramsDerivsFile << "gpp = zeros(" << equation_number() << ", " << dynJacobianColsNbr << ", " - << symbol_table.param_nbr() << ", " << symbol_table.param_nbr() << ");" << endl; + paramsDerivsFile << "gpp = zeros(" << jacobian_params_second_derivatives.size() + << ",5);" << endl; + i = 1; for (third_derivatives_type::const_iterator it = jacobian_params_second_derivatives.begin(); - it != jacobian_params_second_derivatives.end(); it++) + it != jacobian_params_second_derivatives.end(); ++it, i++) { int eq = it->first.first; int var = it->first.second.first; @@ -2824,7 +2829,11 @@ DynamicModel::writeParamsDerivativesFile(const string &basename) const int param1_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param1)) + 1; int param2_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param2)) + 1; - paramsDerivsFile << "gpp(" << eq+1 << ", " << var_col << ", " << param1_col << ", " << param2_col << ") = "; + paramsDerivsFile << "gpp(" << i << ",1)=" << eq+1 << ";" << endl + << "gpp(" << i << ",2)=" << var_col << ";" << endl + << "gpp(" << i << ",3)=" << param1_col << ";" << endl + << "gpp(" << i << ",4)=" << param2_col << ";" << endl + << "gpp(" << i << ",5)="; d2->writeOutput(paramsDerivsFile, oMatlabDynamicModel, params_derivs_temporary_terms); paramsDerivsFile << ";" << endl; } @@ -2834,11 +2843,11 @@ DynamicModel::writeParamsDerivativesFile(const string &basename) const << "if nargout >= 5" << endl; // Write hessian derivatives (only if nargout >= 5) - paramsDerivsFile << "hp = zeros(" << equation_number() << ", " << dynJacobianColsNbr << ", " - << dynJacobianColsNbr << ", " << symbol_table.param_nbr() << ");" << endl; + paramsDerivsFile << "hp = zeros(" << hessian_params_derivatives.size() << ",5);" << endl; + i = 1; for (third_derivatives_type::const_iterator it = hessian_params_derivatives.begin(); - it != hessian_params_derivatives.end(); it++) + it != hessian_params_derivatives.end(); ++it, i++) { int eq = it->first.first; int var1 = it->first.second.first; @@ -2850,7 +2859,11 @@ DynamicModel::writeParamsDerivativesFile(const string &basename) const int var2_col = getDynJacobianCol(var2) + 1; int param_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param)) + 1; - paramsDerivsFile << "hp(" << eq+1 << ", " << var1_col << ", " << var2_col << ", " << param_col << ") = "; + paramsDerivsFile << "hp(" << i << ",1)=" << eq+1 << ";" << endl + << "hp(" << i << ",2)=" << var1_col << ";" << endl + << "hp(" << i << ",3)=" << var2_col << ";" << endl + << "hp(" << i << ",4)=" << param_col << ";" << endl + << "hp(" << i << ",5)="; d2->writeOutput(paramsDerivsFile, oMatlabDynamicModel, params_derivs_temporary_terms); paramsDerivsFile << ";" << endl; }