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: 2438-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.76011142893856
99.79338170109914
99.83081075727979
99.87291844548304
99.90063877565261
99.93182414709338
99.96690768996424
99.9885992355981
100.0
u: 2438-element Vector{Vector{Float64}}:
[1.0, 0.0, 0.0]
[0.9999475332012283, 1.1898673915221327e-6, 3.0383094182944587e-13]
[1.0000090510122377, 2.528630297436693e-6, 1.3720333866760973e-12]
[1.000031435839958, 4.0347548056177184e-6, 3.493226220668491e-12]
[1.00004324588966, 5.729159330790694e-6, 7.043252643182728e-12]
[1.0000320956606195, 7.635238938531201e-6, 1.2509538458335753e-11]
[1.0001249796200822, 9.780575470213636e-6, 2.0525213281515313e-11]
[1.00023159759304, 1.2194602345196305e-5, 3.190527348136014e-11]
[1.00051596934932, 1.4913475154958532e-5, 4.7708347677359926e-11]
[1.0006149508671258, 1.7970118444815603e-5, 6.926927522225845e-11]
⋮
[5.6811288592891245, 5.68209902134136, 1.259681180516766]
[5.726107076899268, 5.738348273371732, 1.2654214233383025]
[5.784729611252468, 5.8030833702839075, 1.2837507921471758]
[6.0167017558166265, 6.030821296202833, 1.3673873756234085]
[5.980109977357129, 5.984322282632437, 1.3679191228258072]
[6.130414465613056, 6.123560318758714, 1.4201979747562499]
[5.916278999262875, 5.899593215460238, 1.358514778772065]
[5.872807522420231, 5.857679642723908, 1.3399201069510303]
[5.902303464345322, 5.888186624012328, 1.3437290066799519]