Here is an example of solving a set of three differential equations using
lsode
. Given the function
## oregonator differential equation
function xdot = f (x, t)
xdot = zeros (3,1);
xdot(1) = 77.27 * (x(2) - x(1)*x(2) + x(1) ...
- 8.375e-06*x(1)^2);
xdot(2) = (x(3) - x(1)*x(2) - x(2)) / 77.27;
xdot(3) = 0.161*(x(1) - x(3));
endfunction
and the initial condition x0 = [ 4; 1.1; 4 ]
, the set of
equations can be integrated using the command
t = linspace (0, 500, 1000);
y = lsode ("f", x0, t);
lsode ran as expected as per below;
octave:7> function xdot = f (x, t)
>
> xdot = zeros (3,1);
>
> xdot(1) = 77.27 * (x(2) - x(1)*x(2) + x(1) ...
> - 8.375e-06*x(1)^2);
> xdot(2) = (x(3) - x(1)*x(2) - x(2)) / 77.27;
> xdot(3) = 0.161*(x(1) - x(3));
>
> endfunction
octave:8> x0 = [ 4; 1.1; 4 ];
octave:9> t = linspace (0, 500, 1000);
octave:10>
octave:10> y = lsode ("f", x0, t);
octave:11>
octave:11>
But when I tried it using ode23, it gave an error (I have exchanged the position of trange and x0 as needed between lsode and ode23 as required)
octave:11> y = ode23 ("f", t, x0);
error: x(2): out of bound 1
error: called from
f at line 5 column 11
starting_stepsize at line 46 column 5
ode23 at line 192 column 25
octave:11>
Regards.