diff --git a/preprocessor/DynamicModel.cc b/preprocessor/DynamicModel.cc
index d7e744960b02a49857734db2563b8c5afe503830..6f98aa32dff10bb1147386309c1a3fe9e68f0f91 100644
--- a/preprocessor/DynamicModel.cc
+++ b/preprocessor/DynamicModel.cc
@@ -1515,6 +1515,42 @@ DynamicModel::writeModelEquationsCode_Block(string &file_name, const string &bin
   code_file.close();
 }
 
+void
+DynamicModel::writeDynamicAuxMFile(const string &dynamic_basename) const
+{
+  string filename = dynamic_basename + "_aux.m";
+  ofstream mDynamicAuxFile;
+  mDynamicAuxFile.open(filename.c_str(), ios::out | ios::binary);
+  if (!mDynamicAuxFile.is_open())
+    {
+      cerr << "Error: Can't open file " << filename << " for writing" << endl;
+      exit(EXIT_FAILURE);
+    }
+  mDynamicAuxFile << "function auxvars = " << dynamic_basename << "_aux(y, x, params, steady_state, it_)"
+                  << endl
+                  << "%" << endl
+                  << "% Status : Computes auxiliary variables for Dynare" << endl
+                  << "%" << endl
+                  << "% Inputs :" << endl
+                  << "%   y         [#dynamic variables by 1] double    vector of endogenous variables in the order stored" << endl
+                  << "%                                                 in M_.lead_lag_incidence; see the Manual" << endl
+                  << "%   x         [nperiods by M_.exo_nbr] double     matrix of exogenous variables (in declaration order)" << endl
+                  << "%                                                 for all simulation periods" << endl
+                  << "%   params    [M_.param_nbr by 1] double          vector of parameter values in declaration order" << endl
+                  << "%   it_       scalar double                       time period for exogenous variables for which to evaluate the model" << endl
+                  << "%" << endl
+                  << "% Outputs:" << endl
+                  << "%   auxvars   [length(M_.aux_vars) by 1]          definitions of auxiliary variables" << endl
+                  << "%" << endl
+                  << "%" << endl
+                  << "% Warning : this file is generated automatically by Dynare" << endl
+                  << "%           from the model file (.mod)" << endl << endl;
+
+  writeModelAuxEquations(mDynamicAuxFile, oMatlabDynamicModel);
+  mDynamicAuxFile << "end" << endl;
+  mDynamicAuxFile.close();
+}
+
 void
 DynamicModel::writeDynamicMFile(const string &dynamic_basename) const
 {
@@ -3523,7 +3559,10 @@ DynamicModel::writeDynamicFile(const string &basename, bool block, bool bytecode
   else if (julia)
     writeDynamicJuliaFile(basename);
   else
-    writeDynamicMFile(t_basename);
+    {
+      writeDynamicMFile(t_basename);
+      writeDynamicAuxMFile(t_basename);
+    }
 }
 
 void
diff --git a/preprocessor/DynamicModel.hh b/preprocessor/DynamicModel.hh
index fbb18b222022faffa8d420d2b5852b9e911f2284..e2672800a31fc1a56a44d480310387bb56a926fb 100644
--- a/preprocessor/DynamicModel.hh
+++ b/preprocessor/DynamicModel.hh
@@ -73,7 +73,8 @@ private:
   //! Store the derivatives or the chainrule derivatives:map<pair< equation, pair< variable, lead_lag >, expr_t>
   typedef map< pair< int, pair< int, int> >, expr_t> first_chain_rule_derivatives_t;
   first_chain_rule_derivatives_t first_chain_rule_derivatives;
-
+  //! Writes auxiliary equations file (Matlab version)
+  void writeDynamicAuxMFile(const string &dynamic_basename) const;
   //! Writes dynamic model file (Matlab version)
   void writeDynamicMFile(const string &dynamic_basename) const;
   //! Writes dynamic model file (Julia version)
diff --git a/preprocessor/ModelTree.cc b/preprocessor/ModelTree.cc
index 21c2d509e3b5a7165eb297fa738e5775b9f532f3..f3704e1102bcb67edde19a2e1c6c7c0e1fde615a 100644
--- a/preprocessor/ModelTree.cc
+++ b/preprocessor/ModelTree.cc
@@ -1264,6 +1264,26 @@ ModelTree::writeModelEquations(ostream &output, ExprNodeOutputType output_type)
     }
 }
 
+void
+ModelTree::writeModelAuxEquations(ostream &output, ExprNodeOutputType output_type) const
+{
+  int eq_ind = 0, av_ind = 0;
+  for (vector<int>::const_iterator it = equations_lineno.begin();
+       it != equations_lineno.end(); it++, eq_ind++)
+    if (*it == -1)
+      {
+        expr_t rhs = equations[eq_ind]->get_arg2();
+        if (IS_JULIA(output_type))
+          output << "  @inbounds ";
+        output << "auxvars" << LEFT_ARRAY_SUBSCRIPT(output_type)
+               << av_ind++ + ARRAY_SUBSCRIPT_OFFSET(output_type)
+               << RIGHT_ARRAY_SUBSCRIPT(output_type)
+               << " = ";
+        rhs->writeOutput(output, output_type, temporary_terms_t());
+        output << ";" << endl;
+      }
+}
+
 void
 ModelTree::compileModelEquations(ostream &code_file, unsigned int &instruction_number, const temporary_terms_t &tt, const map_idx_t &map_idx, bool dynamic, bool steady_dynamic) const
 {
diff --git a/preprocessor/ModelTree.hh b/preprocessor/ModelTree.hh
index ea799585c2b2f0b1cddca7fd678a333e3feccdd5..a485bcd8a3aea2f48a4784fac2116a8d9a13d062 100644
--- a/preprocessor/ModelTree.hh
+++ b/preprocessor/ModelTree.hh
@@ -173,10 +173,11 @@ protected:
   void compileTemporaryTerms(ostream &code_file, unsigned int &instruction_number, const temporary_terms_t &tt, map_idx_t map_idx, bool dynamic, bool steady_dynamic) const;
   //! Adds informations for simulation in a binary file
   void Write_Inf_To_Bin_File(const string &basename, int &u_count_int, bool &file_open, bool is_two_boundaries, int block_mfs) const;
-
   //! Writes model local variables
   /*! No temporary term is used in the output, so that local parameters declarations can be safely put before temporary terms declaration in the output files */
   void writeModelLocalVariables(ostream &output, ExprNodeOutputType output_type, deriv_node_temp_terms_t &tef_terms) const;
+  //! Writes model auxiliary equations
+  void writeModelAuxEquations(ostream &output, ExprNodeOutputType output_type) const;
   //! Writes model equations
   void writeModelEquations(ostream &output, ExprNodeOutputType output_type) const;
   //! Compiles model equations