Skip to contents

SDEProblem(sys, op, tspan) builds a stochastic differential equation problem from a compiled system with brownian variables (or noise equations); op gives initial values and parameters as for ODEProblem(). SDEFunction(sys) builds the drift f(u, p, t) and diffusion g(u, p, t).

Usage

SDEFunction(sys, ..., jac = FALSE, tgrad = FALSE)

SDEProblem(sys, ..., noise_rate_prototype = NULL, noise = NULL)

Arguments

sys

A compiled System, or the drift function f(u, p, t).

...

For systems: op, tspan and solver options stored with the problem (callback, tstops, ...). For functions: g, u0, tspan, p, then options.

jac, tgrad

Generate the drift Jacobian and time gradient.

noise_rate_prototype, noise

Noise shape for raw problems.

Value

An SDEProblem or SDEFunction.

Details

SDEProblem(f, g, u0, tspan, p) with R functions builds a problem without a system. Diagonal noise is the default; give noise_rate_prototype (a matrix with one column per Wiener process) for general noise, or noise = "scalar" for one Wiener process shared by all equations. SDEFunction(f, g, mass_matrix = M) gives a mass matrix (singular for algebraic equations; it multiplies the drift, M du = f dt + M g dW), solved with the implicit methods (ImplicitEM(), ImplicitRKMil(), ...).

Examples

t <- t_nounits; D <- D_nounits
variables("x(t)"); parameters("mu = 1.5", "sigma = 0.3")
B <- Brownian("B")
sys <- mtkcompile(System(list(D(x) ~ mu * x + sigma * x * B), t, name = "gbm"))
prob <- SDEProblem(sys, list(x ~ 1), c(0, 1))
sol <- solve(prob, EM(), dt = 0.01, seed = 1)
tail(sol[x], 1)
#> [1] 5.925108