[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Calling lsode directly from a c++ program via liboctave?
From: |
Douglas Eck |
Subject: |
Re: Calling lsode directly from a c++ program via liboctave? |
Date: |
Thu, 25 Oct 2001 09:47:54 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.4) Gecko/20010913 |
Andrei Romanenko wrote:
Hello!
Great job! I was wondering if there is a quick way to supply parameters
to the ode function. It seems Octave leaves us nothing but declare them
as global. I am afraid it would be a pain to access global variables
from an .oct file (symbol table lookups and stuff like that)...
Have you discovered a better way to do that?
Yes. If you write xdot=f(x,t) in c++ instead of in octave,
it's simply a matter of using a static variable.
Here is my "f" function stripped from a current project:
ColumnVector lbBeatTracker::odeHelper (const ColumnVector& x, double t)
{
//This is the function called multiple times by lsode.
//Each oscillator has a voltage v and recovery w
//These are concatinated such that x=[v1,v2,...,vk,w1,w2,...,wk]
//The parameter epsilon controls the rate of oscillaton
//it is stored in a static column vector epsilons
for (int i=0;i<odeOscCount;i++) {
odeXDot(i) = -x(i)*(x(i)-ODE_FITZ_THOLD) * (x(i)-1.0) - x(i+odeOscCount) +
ODE_FITZ_CVOLT + odeSignal(i);
odeXDot(i+odeOscCount) = odeEpsilons(i) * (x(i)-ODE_FITZ_SHUNT *
x(i+odeOscCount));
}
return odeXDot;
}
Here are the definitions of the variables and constants from the accompanying
header file:
#define ODE_FITZ_THOLD .2
#define ODE_FITZ_CVOLT .112
#define ODE_FITZ_SHUNT 1.2
#define ODE_PTS_PER_SLICE 2
static ColumnVector odeEpsilons; //epsilons
static ColumnVector odeSignal; //signal
static ColumnVector odeXDot; //return value
static int odeOscCount; //oscillator count
You can write to these static variables before calling the
solver. Hope this helps.
Cheers,
Doug
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------