Summary of ODE Options
Solving ODEs frequently requires fine-tuning parameters, adjusting error tolerances,
or passing additional information to the solver. This topic shows how to specify options
for solver functions (ode45
, ode15s
, and so
on), and which differential equation solvers each option is compatible with.
Options Syntax
Use the odeset
function to create an options
structure that you then pass to the solver as the fourth input argument. For
example, to adjust the relative and absolute error tolerances:
opts = odeset(RelTol=1e-2,AbsTol=1e-5); [t,y] = ode45(@odefun,tspan,y0,opts);
If you use the command odeset
with no inputs, then MATLAB® displays a list of the possible values for each option, with default
values indicated by curly braces {}
.
The odeget
function queries the value of
an option in an existing structure, which you can use to dynamically change option
values based on conditions. For example, this code detects whether
Stats
is set to "on"
, and changes the
value if necessary:
if isempty(odeget(opts,"Stats")) odeset(opts,Stats="on") end
Compatibility of Options with Each Solver
Some options in odeset
are generic and compatible with any
solver, while others are solver-specific. This table summarizes the compatibility of
each option with the different solvers.
Option Group | Option | ode45 | ode23 | ode78 | ode89 | ode113 | ode15s | ode23s | ode23t | ode23tb | ode15i |
---|---|---|---|---|---|---|---|---|---|---|---|
Error Control | RelTol |
|
|
|
|
|
|
|
|
|
|
AbsTol |
|
|
|
|
|
|
|
|
|
| |
NormControl |
|
|
|
|
|
|
|
|
|
| |
Solver Output | NonNegative |
|
|
|
|
|
|
|
|
|
|
OutputFcn |
|
|
|
|
|
|
|
|
|
| |
OutputSel |
|
|
|
|
|
|
|
|
|
| |
Refine |
|
|
|
|
|
|
|
|
|
| |
Stats |
|
|
|
|
|
|
|
|
|
| |
Step Size | InitialStep |
|
|
|
|
|
|
|
|
|
|
MaxStep |
|
|
|
|
|
|
|
|
|
| |
MinStep |
|
|
|
|
|
|
|
|
|
| |
Event Location | Events |
|
|
|
|
|
|
|
|
|
|
Jacobian Matrix | Jacobian |
|
|
|
|
|
|
|
|
|
|
JPattern |
|
|
|
|
|
|
|
|
|
| |
Vectorized |
|
|
|
|
|
|
|
|
|
| |
Mass Matrix and DAEs | Mass |
|
|
|
|
|
|
|
|
|
|
MStateDependence |
|
|
|
|
|
|
|
|
|
| |
MvPattern |
|
|
|
|
|
|
|
|
|
| |
MassSingular |
|
|
|
|
|
|
|
|
|
| |
InitialSlope |
|
|
|
|
|
|
|
|
|
| |
Algorithm Options for ode15s
and ode15i | MaxOrder |
|
|
|
|
|
|
|
|
|
|
BDF |
|
|
|
|
|
|
|
|
|
|
* Use the NonNegative
parameter with
ode15s
, ode23t
, and
ode23tb
only for those problems in which there is no mass
matrix.
** The events function for ode15i
must accept a third input
argument for yp
.
Usage Examples
MATLAB includes several example files that show how to use various options.
For example, type edit ballode
to see an example that uses
'Events'
to specify an events function, or edit
batonode
to see an example that uses 'Mass'
to
specify a mass matrix. For a complete summary of example files and which options
they use, see Summary of ODE Examples and Files.