| MATLAB Function Reference | Search  Help Desk |
| ode45, ode23, ode113, ode15s, ode23s, ode23t, ode23tb | Examples See Also |
Syntax
[T,Y] =solver('F',tspan,y0) [T,Y] =solver('F',tspan,y0,options) [T,Y] =solver('F',tspan,y0,options,p1,p2...) [T,Y,TE,YE,IE] =solver('F',tspan,y0,options)
Arguments
Description
[T,Y] = solver('F',tspan,y0)
with tspan = [t0 tfinal] integrates the system of differential equations y' = F(t,y) from time t0 to tfinal with initial conditions y0. 'F' is a string containing the name of an ODE file. Function F(t,y) must return a column vector. Each row in solution array y corresponds to a time returned in column vector t. To obtain solutions at the specific times t0, t1, . . ., tfinal (all increasing or all decreasing), usetspan = [t0 t1 ... tfinal].
[T,Y] = solver('F',tspan,y0,options)
solves as above with default integration parameters replaced by property values specified in options, an argument created with the odeset function (see odeset for details). Commonly used properties include a scalar relative error tolerance RelTol (1e-3 by default) and a vector of absolute error tolerances AbsTol (all components 1e-6 by default).
[T,Y] = solver('F',tspan,y0,options,p1,p2...)
solves as above, passing the additional parameters p1,p2... to the M-file F, whenever it is called. Use options = [] as a place holder if no options are set.
[T,Y,TE,YE,IE] = solver('F',tspan,y0,options)
with the Events property in options set to 'on', solves as above while also locating zero crossings of an event function defined in the ODE file. The ODE file must be coded so that F(t,y,'events') returns appropriate information. See odefile for details. Output TE is a column vector of times at which events occur, rows of YE are the corresponding solutions, and indices in vector IE specify which event occurred.
When called with no output arguments, the solvers call the default output function odeplot to plot the solution as it is computed. An alternate method is to set the OutputFcn property to 'odeplot'. Set the OutputFcn property to 'odephas2' or 'odephas3' for two- or three-dimensional phase plane plotting. See odefile for details.
The solvers of the ODE suite can solve problems of the form M(t, y) y' = F(t, y) with a mass matrix M that is nonsingular and (usually) sparse. Use odeset to set Mass to 'M', 'M(t)', or 'M(t,y)' if the ODE file F.m is coded so that F(t,y,'mass') returns a constant, time-dependent, or time-and-state- dependent mass matrix, respectively. The default value of Mass is 'none'. The ode23s solver can only solve problems with a constant mass matrix M. For examples of mass matrix problems, see fem1ode, fem2ode, or batonode.
For the stiff solvers ode15s, ode23s, ode23t, and ode23tb the Jacobian matrix
is critical to reliability and efficiency so there are special options. Set JConstant to 'on' if
is constant. Set Vectorized to 'on' if the ODE file is coded so that F(t,[y1 y2 ...]) returns [F(t,y1) F(t,y2) ...]. Set JPattern to 'on' if
is a sparse matrix and the ODE file is coded so that F([],[],'jpattern') returns a sparsity pattern matrix of 1's and 0's showing the nonzeros of
. Set Jacobian to 'on' if the ODE file is coded so that F(t,y,'jacobian') returns
.
If M is singular, then M(t) * y' = F(t, y) is a differential algebraic equation (DAE). DAEs have solutions only when y0 is consistent, that is, if there is a vector yp0 such that M(t0) * y0 = f(t0, y0). The ode15s and ode23t solvers can solve DAEs of index 1 provided that M is not state dependent and y0 is sufficiently close to being consistent. If there is a mass matrix, you can use odeset to set the MassSingular property to 'yes', 'no', or 'maybe'. The default value of 'maybe' causes the solver to test whether the problem is a DAE. If it is, the solver treats y0 as a guess, attempts to compute consistent initial conditions that are close to y0, and continues to solve the problem. When solving DAEs, it is very advantageous to formulate the problem so that M is a diagonal matrix (a semi-explicit DAE). For examples of DAE problems, see hb1dae or amp1dae.
tspan, y0, and options in the ODE file (see odefile). If tspan or y0 is empty, then the solver calls the ODE file
[tspan,y0,options] = F([],[],'init')
to obtain any values not supplied in the solver's argument list. Empty arguments at the end of the call list may be omitted. This permits you to call the solvers with other syntaxes such as:
[T,Y] =Integration parameters (solver('F') [T,Y] =solver('F',[],y0) [T,Y] =solver('F',tspan,[],options) [T,Y] =solver('F',[],[],options)
options) can be specified both in the ODE file and on the command line. If an option is specified in both places, the command line specification takes precedence. For information about constructing an ODE file, see odefile.
Options
Different solvers accept different parameters in the options list. For more information, seeodeset and Using MATLAB.Examples
Example 1. An example of a nonstiff system is the system of equations describing the motion of a rigid body without external forces:
rigid containing the equations:
function dy = rigid(t,y) dy = zeros(3,1); % a column vector dy(1) = y(2) * y(3); dy(2) = -y(1) * y(3); dy(3) = -0.51 * y(1) * y(2);In this example we will change the error tolerances with the
odeset command and solve on a time interval of [0 12] with initial condition vector [0 1 1] at time 0.
options = odeset('RelTol',1e-4,'AbsTol',[1e-4 1e-4 1e-5]);
[t,y] = ode45('rigid',[0 12],[0 1 1],options);
Plotting the columns of the returned array Y versus T shows the solution:
plot(T,Y(:,1),'-',T,Y(:,2),'-.',T,Y(:,3),'.')Example 2. An example of a stiff system is provided by the van der Pol equations governing relaxation oscillation. The limit cycle has portions where the solution components change slowly and the problem is quite stiff, alternating with regions of very sharp change where it is not stiff.

vdp1000 containing the equations:
function dy = vdp1000(t,y) dy = zeros(2,1); % a column vector dy(1) = y(2); dy(2) = 1000*(1 - y(1)^2)*y(2) - y(1);For this problem, we will use the default relative and absolute tolerances
1e-3 and 1e-6, respectively) and solve on a time interval of [0 3000] with initial condition vector [2 0] at time 0.
[T,Y] = ode15s('vdp1000',[0 3000],[2 0]);
Plotting the first column of the returned matrix Y versus T shows the solution:
plot(T,Y(:,1),'-o'):
Algorithms
ode45 is based on an explicit Runge-Kutta (4,5) formula, the Dormand-Prince pair. It is a one-step solver - in computing y(tn), it needs only the solution at the immediately preceding time point, y(tn-1). In general, ode45 is the best function to apply as a "first try" for most problems. [1]
ode23 is an implementation of an explicit Runge-Kutta (2,3) pair of Bogacki and Shampine. It may be more efficient than ode45 at crude tolerances and in the presence of moderate stiffness. Like ode45, ode23 is a one-step solver. [2]
ode113 is a variable order Adams-Bashforth-Moulton PECE solver. It may be more efficient than ode45 at stringent tolerances and when the ODE file function is particularly expensive to evaluate. ode113 is a multistep solver - it normally needs the solutions at several preceding time points to compute the current solution. [3]
The above algorithms are intended to solve non-stiff systems. If they appear to be unduly slow, try using one of the stiff solvers below.
ode15s is a variable order solver based on the numerical differentiation formulas, NDFs. Optionally, it uses the backward differentiation formulas, BDFs (also known as Gear's method) that are usually less efficient. Like ode113, ode15s is a multistep solver. If you suspect that a problem is stiff or if ode45 has failed or was very inefficient, try ode15s. [7]
ode23s is based on a modified Rosenbrock formula of order 2. Because it is a one-step solver, it may be more efficient than ode15s at crude tolerances. It can solve some kinds of stiff problems for which ode15s is not effective. [7]
ode23t is an implementation of the trapezoidal rule using a "free" interpolant. Use this solver if the problem is only moderately stiff and you need a solution without numerical damping.
ode23tb is an implementation of TR-BDF2, an implicit Runge-Kutta formula with a first stage that is a trapezoidal rule step and a second stage that is a backward differentiation formula of order two. By construction, the same iteration matrix is used in evaluating both stages. Like ode23s, this solver may be more efficient than ode15s at crude tolerances. [8, 9]
See Also
odeset, odeget, odefile
References
[1] Dormand, J. R. and P. J. Prince, "A family of embedded Runge-Kutta formulae," J. Comp. Appl. Math., Vol. 6, 1980, pp 19-26. [2] Bogacki, P. and L. F. Shampine, "A 3(2) pair of Runge-Kutta formulas," the Initial Value Problem, W. H. Freeman, San Francisco, 1975.
[4] Forsythe, G. , M. Malcolm, and C. Moler, Computer Methods for Mathematical Computations, Prentice-Hall, New Jersey, 1977.
[5] Shampine, L. F. , Numerical Solution of Ordinary Differential Equations, Chapman & Hall, New York, 1994.
[6] Kahaner, D. , C. Moler, and S. Nash, Numerical Methods and Software, Prentice-Hall, New Jersey, 1989.
[7] Shampine, L. F. and M. W. Reichelt, "The MATLAB ODE Suite," (to appear in SIAM Journal on Scientific Computing, Vol. 18-1, 1997).
[8] Shampine, L. F. and M. E. Hosea, "Analysis and Implementation of TR-BDF2," Applied Numerical Mathematics 20, 1996.
[9] Bank, R. E., W. C. Coughran, Jr., W. Fichtner, E. Grosse, D. Rose, and R. Smith, "Transient Simulation of Silicon Devices and Circuits," IEEE Trans. CAD, 4 (1985), pp 436-451