11.1 integrate_ode_rk45, integrate_ode_adams, integrate_ode_bdf ODE integrators
These ODE integrator functions have been replaced by those described in:
11.1.1 Specifying an ordinary differential equation as a function
A system of ODEs is specified as an ordinary function in Stan within the functions block. The ODE system function must have this function signature:
array[] real ode(real time, array[] real state, array[] real theta,
array[] real x_r, array[] int x_i);
The ODE system function should return the derivative of the state with respect to time at the time provided. The length of the returned real array must match the length of the state input into the function.
The arguments to this function are:
time
, the time to evaluate the ODE systemstate
, the state of the ODE system at the time specifiedtheta
, parameter values used to evaluate the ODE systemx_r
, data values used to evaluate the ODE systemx_i
, integer data values used to evaluate the ODE system.
The ODE system function separates parameter values, theta
, from
data values, x_r
, for efficiency in computing the gradients of the
ODE.
11.1.2 Non-stiff solver
array[,] real
integrate_ode_rk45
(function ode, array[] real initial_state, real initial_time, array[] real times, array[] real theta, array[] real x_r, array[] int x_i)
Solves the ODE system for the times provided using the Dormand-Prince
algorithm, a 4th/5th order Runge-Kutta method.
Available since 2.10, deprecated in 2.24
array[,] real
integrate_ode_rk45
(function ode, array[] real initial_state, real initial_time, array[] real times, array[] real theta, array[] real x_r, array[] int x_i, real rel_tol, real abs_tol, int max_num_steps)
Solves the ODE system for the times provided using the Dormand-Prince
algorithm, a 4th/5th order Runge-Kutta method with additional control
parameters for the solver.
Available since 2.10, deprecated in 2.24
array[,] real
integrate_ode
(function ode, array[] real initial_state, real initial_time, array[] real times, array[] real theta, array[] real x_r, array[] int x_i)
Solves the ODE system for the times provided using the Dormand-Prince
algorithm, a 4th/5th order Runge-Kutta method.
Available since 2.10, deprecated in 2.24
array[,] real
integrate_ode_adams
(function ode, array[] real initial_state, real initial_time, array[] real times, array[] real theta, data array[] real x_r, data array[] int x_i)
Solves the ODE system for the times provided using the Adams-Moulton method.
Available since 2.23, deprecated in 2.24
array[,] real
integrate_ode_adams
(function ode, array[] real initial_state, real initial_time, array[] real times, array[] real theta, data array[] real x_r, data array[] int x_i, data real rel_tol, data real abs_tol, data int max_num_steps)
Solves the ODE system for the times provided using the Adams-Moulton
method with additional control parameters for the solver.
Available since 2.23, deprecated in 2.24
11.1.3 Stiff solver
array[,] real
integrate_ode_bdf
(function ode, array[] real initial_state, real initial_time, array[] real times, array[] real theta, data array[] real x_r, data array[] int x_i)
Solves the ODE system for the times provided using the backward differentiation
formula (BDF) method.
Available since 2.10, deprecated in 2.24
array[,] real
integrate_ode_bdf
(function ode, array[] real initial_state, real initial_time, array[] real times, array[] real theta, data array[] real x_r, data array[] int x_i, data real rel_tol, data real abs_tol, data int max_num_steps)
Solves the ODE system for the times provided using the backward differentiation
formula (BDF) method with additional control parameters for the solver.
Available since 2.10, deprecated in 2.24
11.1.4 Arguments to the ODE solvers
The arguments to the ODE solvers in both the stiff and non-stiff cases are as follows.
ode
: function literal referring to a function specifying the system of differential equations with signature:
(real, array[] real, array[] real, data array[] real, data array[] int):array[] real
The arguments represent (1) time, (2) system state, (3) parameters, (4) real data, and (5) integer data, and the return value contains the derivatives with respect to time of the state,
initial_state
: initial state, typearray[] real
,initial_time
: initial time, typeint
orreal
,times
: solution times, typearray[] real
,theta
: parameters, typearray[] real
,data
x_r
: real data, typearray[] real
, data only, anddata
x_i
: integer data, typearray[] int
, data only.
For more fine-grained control of the ODE solvers, these parameters can also be provided:
data
rel_tol
: relative tolerance for the ODE solver, typereal
, data only,data
abs_tol
: absolute tolerance for the ODE solver, typereal
, data only, anddata
max_num_steps
: maximum number of steps to take in the ODE solver, typeint
, data only.
11.1.4.1 Return values
The return value for the ODE solvers is an array of type array[,] real
,
with values consisting of solutions at the specified times.
11.1.4.2 Sizes and parallel arrays
The sizes must match, and in particular, the following groups are of the same size:
state variables passed into the system function, derivatives returned by the system function, initial state passed into the solver, and rows of the return value of the solver,
solution times and number of rows of the return value of the solver,
parameters, real data and integer data passed to the solver will be passed to the system function