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, and which differential equation solvers each option is compatible with.
Options Syntax
Use theodeset
函数创建一个选项结构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 commandodeset
with no inputs, then MATLAB®displays a list of the possible values for each option, with default values indicated by curly braces{}
.
Theodeget
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 whetherStats
is set to'on'
, and changes the value if necessary:
ifisempty(odeget(opts,'Stats')) odeset(opts,'Stats','on')end
Compatibility of Options with Each Solver
Some options inodeset
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 |
|
|
|
|
|
|
|
|
|
|
|
Event Location | Events |
|
|
|
|
|
|
|
|
|
|
Jacobian Matrix | Jacobian |
|
|
|
|
|
|
|
|
|
|
JPattern |
|
|
|
|
|
|
|
|
|
|
|
Vectorized |
|
|
|
|
|
|
|
|
|
|
|
Mass Matrix and DAEs | Mass |
|
|
|
|
|
|
|
|
|
|
MStateDependence |
|
|
|
|
|
|
|
|
|
|
|
MvPattern |
|
|
|
|
|
|
|
|
|
|
|
MassSingular |
|
|
|
|
|
|
|
|
|
|
|
InitialSlope |
|
|
|
|
|
|
|
|
|
|
|
Algorithm Options forode15s andode15i |
MaxOrder |
|
|
|
|
|
|
|
|
|
|
BDF |
|
|
|
|
|
|
|
|
|
|
* Use theNonNegative
parameter withode15s
,ode23t
, andode23tb
only for those problems in which there is no mass matrix.
** The events function forode15i
must accept a third input argument foryp
.
Usage Examples
MATLAB includes several example files that show how to use various options. For example, typeedit ballode
to see an example that uses'Events'
to specify an events function, oredit 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, seeSummary of ODE Examples and Files.