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 by creating @brownian variables in the equations.

using ModelingToolkit, StochasticDiffEq
using ModelingToolkit: t_nounits as t, D_nounits as D

# Define some variables
@parameters σ ρ β
@variables x(t) y(t) z(t)
@brownian a
eqs = [D(x) ~ σ * (y - x) + 0.1a * x,
    D(y) ~ x * (ρ - z) - y + 0.1a * y,
    D(z) ~ x * y - β * z + 0.1a * z]

@mtkbuild de = System(eqs, t)

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, LambaEulerHeun())
retcode: Success
Interpolation: 1st order linear
t: 2463-element Vector{Float64}:
   0.0
   5.106983219771961e-7
   1.0852339342015416e-6
   1.7315864979539305e-6
   2.458733132175368e-6
   3.2767730956744856e-6
   4.197068054610992e-6
   5.232399883414562e-6
   6.397148190818579e-6
   7.707490036648098e-6
   ⋮
  99.76020520500158
  99.78248423962245
  99.80754815357092
  99.83574505676296
  99.867466572854
  99.90187773098936
  99.94059028389164
  99.9841419059067
 100.0
u: 2463-element Vector{Vector{Float64}}:
 [1.0, 0.0, 0.0]
 [0.9999144728150307, 1.1898280493583932e-6, 3.0382089584094353e-13]
 [0.9997819825123007, 2.5280561191730456e-6, 1.371620220565479e-12]
 [0.9997618007829561, 4.033666917559162e-6, 3.4916664358670536e-12]
 [0.9996852283991183, 5.727108264969005e-6, 7.0390268172811014e-12]
 [0.9996310734293139, 7.632177118596285e-6, 1.2500760818651309e-11]
 [0.9996926209608907, 9.776347269963653e-6, 2.0509256266546085e-11]
 [0.9995714754877597, 1.2186554268893688e-5, 3.1871066109772616e-11]
 [0.9993677467265779, 1.489636004279468e-5, 4.7626574481467895e-11]
 [0.9995240455221867, 1.7950526817546017e-5, 6.914257783916137e-11]
 ⋮
 [5.717349443438091, 5.74750463399183, 1.2776786161869145]
 [5.735056566703915, 5.764989410739278, 1.275972354790915]
 [5.771731684427333, 5.801135841393306, 1.2837154829663693]
 [5.673740738527559, 5.702961307704637, 1.2546196810591612]
 [5.59054093139088, 5.624596361310846, 1.2229397321999222]
 [5.636509002121452, 5.677557447421241, 1.2295763824324693]
 [5.750166407952866, 5.793047555968166, 1.2660533134472725]
 [5.870255427216546, 5.905361220182102, 1.3134593440368478]
 [5.940580669574419, 5.970774149498134, 1.337975885828773]