ODE solvers

Integrate differential equations with the solver names and calling conventions you already know.

Nelson’s ode_solvers module provides time integration for explicit, stiff, and implicit problems, together with delay and boundary-value equations. The solvers, their options, and their result objects follow the same interface as the standard array language, so existing differential-equation scripts run unchanged: the same ode45, ode15s, odeset, deval, and event handling, with the same calling conventions.

A first example

Solve y' = -y with y(0) = 1 over the interval [0, 1]:

[t, y] = ode45(@(t, y) -y, [0 1], 1);
y(end)   % 0.367879, which is exp(-1)

A system of equations

The Van der Pol oscillator is a classic two-state system. The right-hand side returns a column vector, one entry per state:

mu  = 1;
vdp = @(t, y) [y(2); mu * (1 - y(1)^2) * y(2) - y(1)];
[t, Y] = ode45(vdp, [0 20], [2; 0]);
plot(t, Y);
The two states of the Van der Pol oscillator plotted against time
The two states of the Van der Pol oscillator, integrated with ode45.

Choose the right solver

The familiar family of solvers covers the usual regimes, and they are interchangeable because they share one calling convention:

On a stiff problem a non-stiff solver is forced into very small steps, while a stiff solver stays efficient. The Van der Pol oscillator with mu = 1000 is stiff, and ode15s integrates it over a long interval in a few hundred steps:

mu  = 1000;
vdp = @(t, y) [y(2); mu * (1 - y(1)^2) * y(2) - y(1)];
[t, Y] = ode15s(vdp, [0 3000], [2; 0]);

Options, events, and dense output

sol = ode45(vdp, [0 20], [2; 0]);
yi  = deval(sol, 10);    % interpolate the solution at t = 10

Beyond initial value problems

An object-oriented workflow

The ode object groups the equation, initial condition, options, and chosen solver into a single problem that you can solve, re-solve, and inspect as a results object. When the optional SUNDIALS backend is built, the object workflow can also select the CVODES and IDAS solvers.


Read the reference for ode45, ode15s, odeset, deval, bvp4c, and dde23.

Back to home