diff --git a/mex/sources/k_order_perturbation/dynamic_m.cc b/mex/sources/k_order_perturbation/dynamic_m.cc
index 1279e522c41d8190500ffecc837be7920fc9daa7..2970f776150b5a54a8d2eca7ddb11181e2eda871 100644
--- a/mex/sources/k_order_perturbation/dynamic_m.cc
+++ b/mex/sources/k_order_perturbation/dynamic_m.cc
@@ -43,7 +43,7 @@ DynamicModelMFile::eval(const Vector &y, const Vector &x, const Vector &modParam
   memcpy((void *) (mxGetPr(prhs[0])), (void *) y.base(), y.length()*sizeof(double));
   memcpy((void *) (mxGetPr(prhs[1])), (void *) x.base(), x.length()*sizeof(double));
   memcpy((void *) (mxGetPr(prhs[2])), (void *) modParams.base(), modParams.length()*sizeof(double));
-  memcpy((void *) (mxGetPr(prhs[3])), (void *) ySteady.base(), modParams.length()*sizeof(double));
+  memcpy((void *) (mxGetPr(prhs[3])), (void *) ySteady.base(), ySteady.length()*sizeof(double));
 
   int retVal = mexCallMATLAB(nlhs_dynamic, plhs, nrhs_dynamic, prhs, DynamicMFilename.c_str());
   if (retVal != 0)