The function lsode can be used Solve ODEs of the form
dx/dt = f (x, t)
using Hindmarsh's ODE solver LSODE.
lsode (fcn, x0, t_out, t_crit)
The first argument is the name of the function to call to compute the vector of right hand sides. It must have the form
xdot = f (x, t)
where xdot and x are vectors and t is a scalar.
The second argument specifies the initial condition, and the third specifies a vector of output times at which the solution is desired, including the time corresponding to the initial condition.
The fourth argument is optional, and may be used to specify a set of times that the ODE solver should not integrate past. It is useful for avoiding difficulties with singularities and points where there is a discontinuity in the derivative.
Tolerances and other options for lsode may be specified using the
function lsode_options.
Here is an example of solving a set of two differential equations using
lsode. The function
function xdot = f (x, t) r = 0.25; k = 1.4; a = 1.5; b = 0.16; c = 0.9; d = 0.8; xdot(1) = r*x(1)*(1 - x(1)/k) - a*x(1)*x(2)/(1 + b*x(1)); xdot(2) = c*a*x(1)*x(2)/(1 + b*x(1)) - d*x(2); endfunction
is integrated with the command
x = lsode ("f", [1; 2], (t = linspace (0, 50, 200)'));
producing a set of 200 values stored in the variable x. Note that this example takes advantage of the fact that an assignment produces a value to store the values of the output times in the variable t directly in the function call The results can then be plotted using the command
plot (t, x)
See Alan C. Hindmarsh, ODEPACK, A Systematized Collection of ODE Solvers, in Scientific Computing, R. S. Stepleman, editor, (1983) for more information about this family of ODE solvers.