Main Content

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 GroupOptionode45ode23ode78ode89ode113ode15sode23sode23tode23tbode15i
Error ControlRelTol

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

AbsTol

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

NormControl

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Solver OutputNonNegative

Supported

Supported

Supported

Supported

Supported

Supported

Unsupported

Supported

Supported

Unsupported

OutputFcn

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

OutputSel

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Refine

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Stats

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Step SizeInitialStep

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

MaxStep

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

MinStep

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Event LocationEvents

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Jacobian MatrixJacobian

Unsupported

Unsupported

Unsupported

Unsupported

Unsupported

Supported

Supported

Supported

Supported

Supported

JPattern

Unsupported

Unsupported

Unsupported

Unsupported

Unsupported

Supported

Supported

Supported

Supported

Supported

Vectorized

Unsupported

Unsupported

Unsupported

Unsupported

Unsupported

Supported

Supported

Supported

Supported

Supported

Mass Matrix and DAEsMass

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Unsupported

MStateDependence

Supported

Supported

Supported

Supported

Supported

Supported

Unsupported

Supported

Supported

Unsupported

MvPattern

Unsupported

Unsupported

Unsupported

Unsupported

Unsupported

Supported

Unsupported

Supported

Supported

Unsupported

MassSingular

Unsupported

Unsupported

Unsupported

Unsupported

Unsupported

Supported

Unsupported

Supported

Unsupported

Unsupported

InitialSlope

Unsupported

Unsupported

Unsupported

Unsupported

Unsupported

Supported

Unsupported

Supported

Unsupported

Unsupported

Algorithm Options for ode15s and ode15iMaxOrder

Unsupported

Unsupported

Unsupported

Unsupported

Unsupported

Supported

Unsupported

Unsupported

Unsupported

Supported

BDF

Unsupported

Unsupported

Unsupported

Unsupported

Unsupported

Supported

Unsupported

Unsupported

Unsupported

Unsupported

* 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.

See Also

|

Related Topics