MATLAB ODE Solver Selection: ode45, ode15s, or ode23t?
Choose among ode45, ode15s, and ode23t for MATLAB initial-value problems based on stiffness, mass matrix support, and accuracy validation.
18 Feb 2026, 07:27 UTC

The decision
You need to integrate an initial-value problem in MATLAB, typically written as y′ = f(t, y) with a known starting vector y(t0). The solver you choose changes runtime and, on stiff problems, can change correctness. A stiff problem contains dynamics that evolve at very different speeds, forcing an explicit solver to take extremely small steps to remain stable.
Useful takeaway: start with ode45 for smooth, non-stiff systems; switch to ode15s if the problem is stiff, is a differential-algebraic equation, or uses a consistent mass matrix; consider ode23t for moderate stiffness when you can accept more numerical damping. Always validate by repeating the run with tighter tolerances.
Constraints before you choose
- All solvers covered here are variable-step; MATLAB does not offer fixed-step ode45-style integration through this interface.
- The right-hand side must return a column vector. Returning a row vector can trigger dimension errors or silently wrong results.
- Event functions require the odeset 'Events' option.
- You can supply an analytic Jacobian or let MATLAB estimate it; analytic Jacobians usually reduce iterations for implicit solvers.
Supported options compared
| Solver | Method class | Stiffness | Mass matrix | Typical behavior |
|---|---|---|---|---|
| ode45 | Explicit Runge-Kutta | Non-stiff | No | Low cost per step; many tiny steps or failure on stiff systems |
| ode15s | Implicit BDF/NDF | Stiff | Yes | Higher cost per step due to nonlinear solves; robust on stiff problems |
| ode23t | Implicit trapezoidal | Moderate | Yes | Medium cost; less accurate than ode15s on highly stiff dynamics |
Trade-offs
ode45 is usually fastest on smooth, non-stiff problems because each step is cheap and it takes large steps where the solution is smooth. On a stiff system it may run to completion without an error while producing inaccurate results, or it may fail because the step size collapses.
ode15s solves an implicit system at every step, so each step is more expensive, but it remains stable when explicit solvers break down. It also handles differential-algebraic equations and problems with a mass matrix M*y′ = f(t, y).
ode23t sits between the two: it supports mass matrices and moderate stiffness at a lower per-step cost than ode15s, but it introduces more numerical damping and is less reliable for very stiff dynamics.
Implementation and validation example
Run the following in the MATLAB Command Window or a script file. No special toolbox permissions are required beyond a base MATLAB license.
% Define a non-stiff harmonic oscillator: y'' = -y
f = @(t, y) [y(2); -y(1)];
% Tight accuracy settings
opts = odeset('RelTol', 1e-6, 'AbsTol', 1e-8);
% Integrate from t = 0 to 10, starting at y = [1; 0]
[t, y] = ode45(f, [0 10], [1; 0], opts);
% Plot position and velocity
plot(t, y(:, 1), t, y(:, 2));
xlabel('Time'); ylabel('State'); legend('y', 'dy/dt');
To validate, repeat the integration with tighter tolerances and compare the final state. If the difference is smaller than your requested tolerance, the looser run is trustworthy.
optsTight = odeset('RelTol', 1e-8, 'AbsTol', 1e-10);
[tTight, yTight] = ode45(f, [0 10], [1; 0], optsTight);
diffNorm = norm(y(end, :) - yTight(end, :));
fprintf('Final-state difference: %g\n', diffNorm);
Expected check: diffNorm should be near the level of the looser tolerance (around 1e-6 or smaller). If the difference is much larger than RelTol, the problem may be stiff or the tolerances too loose; repeat with ode15s.
Diagnostic: detect stiffness with solver statistics
Enable odeset 'Stats','on' to compare step counts, failures, and function evaluations. A stiff problem typically makes ode45 take many more steps than ode15s, or causes ode45 to issue a failure warning.
optsStats = odeset('RelTol', 1e-3, 'AbsTol', 1e-5, 'Stats', 'on');
[t45, y45] = ode45(f, [0 10], [1; 0], optsStats);
[t15s, y15s] = ode15s(f, [0 10], [1; 0], optsStats);
Compare the Command Window output from both runs. If ode45 reports thousands of steps while ode15s reports far fewer, the system is stiff and ode15s is the better choice.
Limitations
- MATLAB Coder supports only a subset of these solvers and odeset options for code generation; verify target support before deploying solver-based generated code.
- These solvers are for initial-value problems, not boundary-value problems (use bvp4c or bvp5c for those).
- No rollback is needed because selecting and running a solver does not modify system state or files.
Practical check
Run doc ode45 in your installed MATLAB release to confirm the exact solver list and odeset options available, since supported options can vary by release.