kenny
01-14-2004, 08:59 AM
Hi there,
I am using the C version of odeint on Windows w/ the Dev-C++ compiler. I can execute the bessj examples in the Example Book as well as simple elementary functions (sin(x), exp(x), x^2, etc...). However, I can't seem to do this for the lotka volterra predator prey equations, given by
V'(t)= a*V(t)- (B/N) P(t)*V(t) (prey dynamics)
P'(t)= e*P(t)*(B/N)* V(t) - d*P(t) (pred dynamics)
where a, B,e,d are constants.
I feel the problem has to be with the way I am setting up the derivs fn.
Specifically, setting a=.5, b=1, e=.5, d=.1, I have:
#define N 2 /* for no. of equations, variables */
void derivs(float x, float y[], float dydx[])
{
nrhs++;
dydx[1]=y[2]*y[1]*0.5*(1/4000)-0.1*y[1];
dydx[2]=y[2]*0.5-(1/4000)*y[2]*y[1];
}
and proceed to call odeint with trivial modifications in the main{} fn from the example in the NR Example Book (a variant available online is: http://www.pma.caltech.edu/~physlab/ph21/21_2_handout.pdf). However, I don't get the right results and y[1] -> inf & y[2] -> 0 monotonically as opposed to cyclical dynamics.
Thanks much in advance,
K
I am using the C version of odeint on Windows w/ the Dev-C++ compiler. I can execute the bessj examples in the Example Book as well as simple elementary functions (sin(x), exp(x), x^2, etc...). However, I can't seem to do this for the lotka volterra predator prey equations, given by
V'(t)= a*V(t)- (B/N) P(t)*V(t) (prey dynamics)
P'(t)= e*P(t)*(B/N)* V(t) - d*P(t) (pred dynamics)
where a, B,e,d are constants.
I feel the problem has to be with the way I am setting up the derivs fn.
Specifically, setting a=.5, b=1, e=.5, d=.1, I have:
#define N 2 /* for no. of equations, variables */
void derivs(float x, float y[], float dydx[])
{
nrhs++;
dydx[1]=y[2]*y[1]*0.5*(1/4000)-0.1*y[1];
dydx[2]=y[2]*0.5-(1/4000)*y[2]*y[1];
}
and proceed to call odeint with trivial modifications in the main{} fn from the example in the NR Example Book (a variant available online is: http://www.pma.caltech.edu/~physlab/ph21/21_2_handout.pdf). However, I don't get the right results and y[1] -> inf & y[2] -> 0 monotonically as opposed to cyclical dynamics.
Thanks much in advance,
K