diff --git a/preprocessor/StaticModel.cc b/preprocessor/StaticModel.cc
index 5d74d2d8fc26fc2433be1ed38b546805c5fad5e4..20a271943bc44bce60bed4b5edad25a4f4075553 100644
--- a/preprocessor/StaticModel.cc
+++ b/preprocessor/StaticModel.cc
@@ -1193,7 +1193,7 @@ StaticModel::writeStaticMFile(const string &func_name) const
     }
 
   output << "  if ~isreal(g1)" << endl
-         << "    g1 = real(g1)+2*imag(g1);" << endl
+         << "    g1 = real(g1)+imag(g1).^2;" << endl
          << "  end" << endl
          << "end" << endl
          << "if nargout >= 3," << endl