rlsoda: Integrate ODE with lsoda

Description Usage Arguments Value

View source: R/rlsoda.R

Description

Integrate an ODE with lsoda.

Usage

1
2
3
4
5
6
7
rlsoda(y, times, func, parms, ..., n_out = 0L, output = NULL,
  rtol = 1e-06, atol = 1e-06, step_size_min = 0, step_size_max = 0,
  step_size_initial = 0, step_max_n = 100000L, tcrit = NULL,
  dllname = "", parms_are_real = TRUE, ynames = TRUE, outnames = NULL,
  by_column = FALSE, return_initial = FALSE, return_statistics = FALSE,
  return_time = FALSE, return_output_with_y = FALSE,
  deSolve_compatible = FALSE)

Arguments

y

Initial conditions for the integration

times

Times where output is needed. Unlike deSolve we won't actually stop at these times, but instead interpolate back to get the result.

func

Function to integrate. Can be an R function of arguments t, y, parms, returning a numeric vector, or it can be the name or address of a C function with arguments size_t n, double t, const double *y, double *dydt, void *data.

parms

Parameters to pass through to the derivatives.

...

Dummy arguments - nothing is allowed here, but this means that all further arguments must be specified by name (not order) so I can easily reorder them later on.

n_out

Number of "output" variables (not differential equation variables) to compute via the routine output.

output

The output routine; either an R function taking arguments t, y, parms or the name/address of a C function taking arguments size_t n, double t, const double *y, size_t n_out, double *out, void *data.

rtol

The per-step relative tolerance. The total accuracy will be less than this.

atol

The per-step absolute tolerance.

step_size_min

The minimum step size. The actual minimum used will be the largest of the absolute value of this step_size_min or .Machine$double.eps. If the integration attempts to make a step smaller than this, it will throw an error, stopping the integration (note that this differs from the treatment of hmin in deSolve::lsoda).

step_size_max

The largest step size. By default there is no maximum step size (Inf) so the solver can take as large a step as it wants to. If you have short events you want the solver to notice, then specify a smaller maximim step size here (or use tcrit below).

step_size_initial

The initial step size. By default the integrator will guess the step size automatically, but one can be given here instead.

step_max_n

The maximum number of steps allowed. If the solver takes more steps than this it will throw an error. Note the number of evaluations of func will be a multiple of the number of steps.

tcrit

An optional vector of critical times that the solver must stop at (rather than interpolating over). This can include an end time that we can't go past, or points within the integration that must be stopped at exactly (for example cases where the derivatives change abruptly). Note that this differs from the interpretation of this parameter in deSolve; there tcrit is a single time that integration may not go past – with dde we never go past the final time, and this is just for times that fall within the range of times in times.

dllname

Name of the shared library (without extension) to find the function func (and output if given) in the case where func refers to compiled function.

parms_are_real

Logical, indicating if parms should be treated as vector of doubles by func (when it is a compiled function). If TRUE (the default), then REAL(parms), which is double* is passed through. If FALSE then if params is an externalptr type (EXTPTRSXP) we pass through the result of R_ExternalPtrAddr, otherwise we pass params through unmodified as a SEXP. In the last case, in your target function you will need to include <Rinternals.h>, cast to SEXP and then pull it apart using the R API (or Rcpp).

ynames

Logical, indicating if the output should be named following the names of the input vector y. Alternatively, if ynames is a character vector of the same length as y, these will be used as the output names.

outnames

An optional character vector, used when n_out is greater than 0, to name the model output matrix.

by_column

Logical, indicating if the output should be returned organised by column (rather than row). This incurs a slight cost for transposing the matrices. If you can work with matrices that are transposed relative to deSolve, then set this to FALSE.

return_initial

Logical, indicating if the output should include the initial conditions (like deSolve).

return_statistics

Logical, indicating if statistics about the run should be included. If TRUE, then an integer vector containing the number of target evaluations, steps, accepted steps and rejected steps is returned (the vector is named).

return_time

Logical, indicating if a row (or column if by_column is TRUE) representing time is included (this matches deSolve).

return_output_with_y

Logical, indicating if the output should be bound together with the returned matrix y (as it is with deSolve). Otherwise output will be returned as the attribute output.

deSolve_compatible

Logical, indicating if we should run in "deSolve compatible" output mode. This enables the options by_column, return_initial, return_time and return_output_with_y. This affects only some aspects of the returned value, and not the calculations themselves.

Value

At present the return value is transposed relative to deSolve. This might change in future.


richfitz/rlsoda documentation built on May 27, 2019, 8:41 a.m.