Node:Ordinary Differential Equations, Next:Differential-Algebraic Equations, Up:Differential Equations
The function lsode can be used to solve ODEs of the form
dx -- = f (x, t) dt
using Hindmarsh's ODE solver LSODE.
| [x, istate, msg] lsode (fcn, x_0, t, t_crit) | Loadable Function |
Solve the set of differential equations
dx -- = f(x, t) dt with
x(t_0) = x_0 The solution is returned in the matrix x, with each row corresponding to an element of the vector t. The first element of t should be t_0 and should correspond to the initial state of the system x_0, so that the first row of the output is x_0. The first argument, fcn, is a string that names the function to
call to compute the vector of right hand sides for the set of equations.
The function must have the form
xdot = f (x, t) in which xdot and x are vectors and t is a scalar. If fcn is a two-element string array, the first element names the
function f described above, and the second element names a function
to compute the Jacobian of f. The Jacobian function must have the
form
jac = j (x, t) in which jac is the matrix of partial derivatives
| df_1 df_1 df_1 |
| ---- ---- ... ---- |
| dx_1 dx_2 dx_N |
| |
| df_2 df_2 df_2 |
| ---- ---- ... ---- |
df_i | dx_1 dx_2 dx_N |
jac = ---- = | |
dx_j | . . . . |
| . . . . |
| . . . . |
| |
| df_N df_N df_N |
| ---- ---- ... ---- |
| dx_1 dx_2 dx_N |
The second and third arguments specify the intial state of the system, x_0, and the initial value of the independent variable t_0. 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. After a successful computation, the value of istate will be 2 (consistent with the Fortran version of LSODE). If the computation is not successful, istate will be something other than 2 and msg will contain additional information. You can use the function |
| lsode_options (opt, val) | Loadable Function |
When called with two arguments, this function
allows you set options parameters for the function lsode.
Given one argument, lsode_options returns the value of the
corresponding option. If no arguments are supplied, the names of all
the available options and their current values are displayed.
Options include
|
Here is an example of solving a set of three differential equations using
lsode. Given the function
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);
If you try this, you will see that the value of the result changes
dramatically between t = 0 and 5, and again around t = 305.
A more efficient set of output points might be
t = [0, logspace (-1, log10(303), 150), \
logspace (log10(304), log10(500), 150)];
See Alan C. Hindmarsh, ODEPACK, A Systematized Collection of ODE
Solvers, in Scientific Computing, R. S. Stepleman, editor, (1983) for
more information about the inner workings of lsode.