diff liboctave/LSODE.cc @ 2343:d7592de300ea

[project @ 1996-07-24 21:42:44 by jwe]
author jwe
date Wed, 24 Jul 1996 21:44:51 +0000
parents 1b57120c997b
children 8b262e771614
line wrap: on
line diff
--- a/liboctave/LSODE.cc	Wed Jul 24 18:08:39 1996 +0000
+++ b/liboctave/LSODE.cc	Wed Jul 24 21:44:51 1996 +0000
@@ -71,6 +71,8 @@
 
   liw = 20 + n;
   lrw = 22 + n * (9 + n);
+
+  sanity_checked = 0;
 }
 
 LSODE::LSODE (const ColumnVector& state, double time, const ODEFunc& f)
@@ -91,6 +93,8 @@
 
   liw = 20 + n;
   lrw = 22 + n * (9 + n);
+
+  sanity_checked = 0;
 }
 
 void
@@ -116,7 +120,7 @@
 lsode_f (const int& neq, const double& time, double *,
 	 double *deriv, int& ierr) 
 {
-  ColumnVector tmp_deriv (neq);
+  ColumnVector tmp_deriv;
 
   // NOTE: this won't work if LSODE passes copies of the state vector.
   //       In that case we have to create a temporary vector object
@@ -198,6 +202,22 @@
   user_fun = function ();
   user_jac = jacobian_function ();
 
+  if (! sanity_checked)
+    {
+      ColumnVector xdot = (*user_fun) (x, t);
+
+      if (x.length () != xdot.length ())
+	{
+	  (*current_liboctave_error_handler)
+	    ("lsode: inconsistent sizes for state and derivative vectors");
+
+	  integration_error = 1;
+	  return retval;
+	}
+
+      sanity_checked = 1;
+    }
+
   // Try 5000 steps before giving up.
 
   iwork.elem (5) = 5000;