Modeling with Stochasticity

All models with ODESystem are deterministic. SDESystem adds another element to the model: randomness. This is a stochastic differential equation which has a deterministic (drift) component and a stochastic (diffusion) component. Let's take the Lorenz equation from the first tutorial and extend it to have multiplicative noise.

using ModelingToolkit, StochasticDiffEq

# Define some variables
@parameters σ ρ β
@variables t x(t) y(t) z(t)
D = Differential(t)

eqs = [D(x) ~ σ * (y - x),
    D(y) ~ x * (ρ - z) - y,
    D(z) ~ x * y - β * z]

noiseeqs = [0.1 * x,
    0.1 * y,
    0.1 * z]

@named de = SDESystem(eqs, noiseeqs, t, [x, y, z], [σ, ρ, β])

u0map = [
    x => 1.0,
    y => 0.0,
    z => 0.0,
]

parammap = [
    σ => 10.0,
    β => 26.0,
    ρ => 2.33,
]

prob = SDEProblem(de, u0map, (0.0, 100.0), parammap)
sol = solve(prob, SOSRI())
retcode: Success
Interpolation: 1st order linear
t: 17517-element Vector{Float64}:
   0.0
   0.0007146315987816352
   0.0008575579185379623
   0.0010183500282638302
   0.0011992411517054316
   0.0014027436655772332
   0.00163168399368301
   0.0018880013908632763
   0.002169046658110038
   0.0024735680146058996
   ⋮
  99.93900128218822
  99.94851757557012
  99.95821119151138
  99.9663119161273
  99.97436005954434
  99.98264588729006
  99.99090061999634
  99.99845215143192
 100.0
u: 17517-element Vector{Vector{Float64}}:
 [1.0, 0.0, 0.0]
 [0.9954617581547094, 0.0016671999537899494, 5.897151541810182e-7]
 [0.9932628088352334, 0.0019963418718315635, 8.462207766419522e-7]
 [0.9915158979901165, 0.0023667155493900917, 1.1874279472579343e-6]
 [0.9890310721616313, 0.002785574922615009, 1.6414591910415459e-6]
 [0.987219287803627, 0.003249141017681429, 2.2386707358968483e-6]
 [0.9864724243701982, 0.0037673563631499068, 3.014410949988464e-6]
 [0.9817084016144879, 0.004351598152068503, 4.017393702041506e-6]
 [0.9804900132608751, 0.0049882533018835535, 5.277501485226151e-6]
 [0.9777291174068103, 0.005692271837458676, 6.8201486596624074e-6]
 ⋮
 [5.9465973023972944, 6.066754610127474, 1.3867407351998993]
 [5.983649225747509, 6.157277134439649, 1.401532813667108]
 [6.0043453337244745, 6.219871478179279, 1.4069170139900289]
 [5.957270646063816, 6.201222476360732, 1.424735264843217]
 [5.991377891332473, 6.145316049132238, 1.4400541027698543]
 [5.9959121303262854, 6.104874685920632, 1.4492808022749135]
 [6.032227052813649, 6.038771211403315, 1.424053763398826]
 [6.067375143059037, 5.996162554234371, 1.4021319088456397]
 [6.009666723700338, 5.991071514816068, 1.4022718847676745]