[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Calling lsode directly from a c++ program via liboctave?

From: Douglas Eck
Subject: Calling lsode directly from a c++ program via liboctave?
Date: Tue, 23 Oct 2001 11:22:08 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.4) Gecko/20010913

I need to call the fortran lsode from a dynamically-linked c++ program.
Right now the following code works, but it parses an octave .m program
as the user function. I want to define the function directly
in c++ and call lsode directly. I found the code particularly hard
to understand here presumably because the whole ODE class hierarchy
is not optimized for my reading pleasure but for speed.

Here's my working code as a DLD function (necessary to pass
in the user function). . .

//cribbed directly from John's lsode.oct code
DEFUN_DLD (fitz, args,,
"Fitzhugh-Nagumo oscillator. Calling syntax: fitz(fn_name,x0,t)")
  octave_value_list retval;
  lsode_fcn = extract_function
    (args(0), "lsode", "__lsode_fcn__",
     "function xdot = __lsode_fcn__ (x, t) xdot = ",
     "; endfunction");
  ColumnVector state (args(1).vector_value ());
  ColumnVector out_times (args(2).vector_value ());
  double tzero = out_times (0);
  int nsteps = out_times.capacity ();
  ODEFunc func (lsode_user_function);
  LSODE ode (state, tzero, func);
  ode.copy (lsode_opts);
  int nstates = state.capacity ();
  Matrix output (nsteps, nstates + 1);
  output = ode.integrate (out_times);
  retval.resize (1);
  retval(0) = output;
  return retval;

Pointers to pointers?

Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:
How to fund new projects:
Subscription information:

reply via email to

[Prev in Thread] Current Thread [Next in Thread]