Skip to contents

solve(prob, alg) solves a problem built by ODEProblem() and the other problem constructors. It is a method of the base R generic base::solve(), so solve() keeps working for matrices and for symcompR expressions.

Usage

# S3 method for class 'DAEProblem'
solve(a, b, ...)

# S3 method for class 'ImplicitDiscreteProblem'
solve(a, b, ...)

# S3 method for class 'ODEProblem'
solve(a, b, ...)

Arguments

a

A problem.

b

An algorithm such as Tsit5(); DefaultODEAlgorithm() when missing.

...

Solver options: saveat (times to save at), abstol, reltol, dt (initial or fixed step), dtmax, dtmin, maxiters, tstops, callback, save_everystep, save_start, save_end, dense, adaptive, step_limiter (a function limiter(u, integ, p, t) returning the state to keep after each accepted step), the controller settings qmin, qmax, gamma, beta1, beta2, and the step checks isoutofdomain (a function (u, p, t); a step whose state it flags is rejected), unstable_check (a function (dt, u, p, t); the solve ends with "Unstable" when it returns TRUE after a step), internalnorm (the error norm, a function (u, t)) and force_dtmin. An unknown keyword is an error; kwargshandle = "warn" or "silent" warns or ignores it. A problem without unknowns returns its save times without integrating. The solution interpolates derivatives too: sol(t, deriv = 1).

Value

A solution object. Its retcode is one of "Success", "Terminated", "MaxIters", "DtLessThanMin", "Unstable", "InitialFailure" or "ConvergenceFailure"; sol$stats counts function evaluations (nf), Jacobians (njacs), linear solves (nsolve), factorizations (nw), accepted (naccept) and rejected (nreject) steps.

Examples

prob <- ODEProblem(function(u, p, t) -p * u, 1, c(0, 1), p = 2)
sol <- solve(prob, Tsit5(), reltol = 1e-8)
sol(1) - exp(-2)
#> [1] 6.972457e-09