Criteria for Solver Selection: Explicit vs. Implicit Integration

Ordinary differential equation (ODE) solvers in MATLAB operate through two fundamentally distinct numerical approaches: explicit formulas (like ode45, ode23, ode113) and implicit formulas (such as ode15s, ode23s, ode23t, ode23tb). Choosing the incorrect solver family is the leading cause of simulations freezing, step sizes collapsing toward machine epsilon, or execution times running hours longer than necessary.

An ODE system $\dot{y} = f(t,y)$ is mathematically stiff when its Jacobians exhibit eigenvalues $\lambda_i$ whose real parts are negative and widely separated in scale:

$$ ext{Stiffness Ratio } S = rac{\max_i | ext{Re}(\lambda_i)|}{\min_i | ext{Re}(\lambda_i)|} \gg 10^3$$

For non-stiff systems with $S < 10^3$, ode45 is the optimal first choice. When $S > 10^3$, explicit solvers must reduce step size to satisfy stability constraints dictated by the fastest decaying transient, even after that transient has physically died out. In such scenarios, ode15s stabilizes the integration and delivers execution speedups of 10x to 1000x.

Why ode45 Collapses on Stiff Differential Equations

The ode45 algorithm implements the Dormand-Prince explicit Runge-Kutta $(4,5)$ pair. Explicit methods evaluate the state derivative at future intermediate stages using only known values from the current step:

$$y_{n+1} = y_n + h \sum_{i=1}^s b_i k_i, \quad k_i = f\left(t_n + c_i h, \, y_n + h \sum_{j=1}^{i-1} a_{ij} k_j ight)$$

When applied to the linear test equation $\dot{y} = \lambda y$ where $ ext{Re}(\lambda) < 0$, the numerical solution remains bounded only if the product of time step $h$ and eigenvalue $\lambda$ lies within the explicit stability region. For ode45, this imposes a strict step-size limit: $h \le 2.785 / |\lambda_{\max}|$.

If a system has an active electrical or chemical mode with $|\lambda_{\max}| = 10^6 ext{ s}^{-1}$, ode45 cannot take a step larger than $2.78 ext{ microseconds}$, even if the physical dynamics of interest occur over a timeframe of 60 seconds. Taking millions of unnecessary micro-steps causes numerical truncation error accumulation and step-size collapse.

How ode15s Solves Stiff Equations

The ode15s solver is a variable-order quasi-constant step size implementation of Numerical Differentiation Formulas (NDFs) of orders 1 through 5, with an option to select classical Backward Differentiation Formulas (BDFs). Implicit methods evaluate derivatives at the unknown future state:

$$y_{n+1} = \sum_{i=1}^k lpha_i y_{n+1-i} + h eta f(t_{n+1}, y_{n+1})$$

Because $y_{n+1}$ appears on both sides of the equation, the solver solves a non-linear algebraic system at every integration step using a simplified Newton-Raphson iteration. The stability region of implicit NDFs covers the entire negative half of the complex plane ($A(lpha)$-stability), meaning the step size $h$ is constrained only by the required local truncation accuracy, not by stability boundaries.

Analytical Jacobian Acceleration

By default, ode15s approximates the system Jacobian matrix $J = rac{\partial f}{\partial y}$ using finite differences. For an $n$-dimensional state space, this requires $n$ auxiliary function evaluations per iteration. Supplying an analytical Jacobian via odeset('Jacobian', @my_jacobian) removes finite difference overhead and guarantees quadratic Newton convergence.

Solver Comparison Matrix

Solver Algorithm Type Order of Accuracy Best Suited For Recommended Use Case
ode45 Explicit Runge-Kutta Medium (4th/5th) Non-stiff smooth problems Orbital trajectories, rigid body kinematics, smooth dynamics
ode15s Implicit NDFs / BDFs Variable (1st to 5th) Stiff systems, DAEs Chemical reaction kinetics, thermal modeling, power systems
ode23tb Implicit Runge-Kutta (TR-BDF2) Low-Medium (2nd) Moderately stiff with discontinuities Simscape physical circuits, switched converters, hydraulics
ode23s Modified Rosenbrock Low (2nd) Stiff problems with crude tolerances Fast scoping, real-time approximations

Diagnostic Workflow: When Your Simulation Stalls

  1. Check the eigenvalues of the linearized Jacobian near the initial conditions. If the ratio between maximum and minimum negative real parts exceeds $10^3$, immediately switch from ode45 to ode15s.
  2. If ode15s produces numerical oscillations near discontinuities, switch to ode23tb, which provides stronger numerical damping.
  3. Set RelTol = 1e-4 and AbsTol = 1e-6. Overly tight tolerances (such as 1e-10) force solvers into artificial step reduction.
  4. Supply the analytical Jacobian matrix whenever algebraic expressions permit.