Time for action - revisiting the Sel'kov model
1. In Chapter 5, we discussed how to solve a differential equation system using
lsode
. Specifically, we usedlsode
to solve the Sel'kov model. There the differential equation system was specified in an m-function, but we can also implement it using the C++ interface. Recall that in the original function, we used the global variableglobal_b
in the function, so the C++ implementation needs to retrieve this variable from the Octave workspace as well.Code Listing 8.5 #include <octave/oct.h> #1 #2 DEFUN_DLD(selkovo, argv, , "Usage: y = selkovo(x)"){ #3 octave_value_list retval; #4 #5 octave_value boct = get_global_value("global_b"); #6 double b = boct.scalar_value(); #7 #8 ColumnVector x( argv(0).vector_value() ); #9 ColumnVector f(2); #10 #11 const double *xval = x.fortran_vec(); #12 double *fval = f.fortran_vec(); #13 #14 double xt = 0.1*xval[1] + xval[0]*xval[0]*xval[1]; #15 #16 fval[0] = -xval[0] + xt; #17 fval[1] = b - xt; #18 #19 retval...