I am trying to use the Sundials ODE solver libraries in order to approximate the dynamics of an extension to the multi species Lotka-Volterra competition equations. E.g. in the case of two species
dx1/dt = r1 * x1 * (1 - (x1 + a12 * x2))
dx2/dt = r2 * x2 * (1 - (x2 + a21 * x1))
or...
dx/dt = r * x * (1 - A * x)
(where K = a11 = a22 = 1)
From what I understand the Sundials ODE solver expects an object of class ODE_vector, the elements of which represent the various state variables of the system, in this case x1 and x2 and I have no problem getting the solver to approximate the trajectories of the two species' populations if I program each parameter (r1, r2, a12, a21) as unique objects as in the following code:
int community::dynamics(ODE_vector const & state, ODE_vector & time_derivative) {
double r1 = 0.5;
double r2 = 0.2;
double a12 = 0.2;
double a21 = 0.2;
time_derivative[0] = r1 * state[0] * (1 - (state[0] + a12 * state[1]));
time_derivative[1] = r2 * state[1] * (1 - (state[1] + a21 * state[0]));
return 0;
};
... where time_derivative
and state
are members of the Sundials class ODE
.
Can anyone show me how to adapt the code to get the system of ODEs into matrix form, i.e. so that r1, r2, a12 and a21 are in the form r and A? I've been told to convert from ODE_vector to armadillo vector/matrix objects using "Advanced constructors" (e.g. 1) but it's one thing to know that and another to successfully implement it!!
Thanks!