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: 18070-element Vector{Float64}:
0.0
0.0007146315987816352
0.0008575579185379623
0.0010183500282638302
0.0011992411517054316
0.0014027436655772332
0.00163168399368301
0.001887572199173422
0.0021682290001242025
0.0024720985965641
⋮
99.9521975108444
99.95869724391561
99.96537788451131
99.97102835496469
99.9765427892382
99.98254416100352
99.98837682076059
99.9949385629873
100.0
u: 18070-element Vector{Vector{Float64}}:
[1.0, 0.0, 0.0]
[0.9963223091252177, 0.0016644700657199812, 5.874424198026072e-7]
[0.9962693197077462, 0.0019967340186770417, 8.45519300140895e-7]
[0.9938484041123137, 0.0023727294566686145, 1.1922938817565319e-6]
[0.9927448038752441, 0.0027919204670022527, 1.6479179893107688e-6]
[0.9954205559211698, 0.0032623297806698825, 2.2515139694828106e-6]
[0.9923302704703075, 0.0037919330892690188, 3.0384160767481404e-6]
[0.9883826737814128, 0.004387885686929395, 4.053516414237953e-6]
[0.9886695487561913, 0.0050282219442913945, 5.324794361497994e-6]
[0.9828674182118309, 0.005715099842175463, 6.893281345702324e-6]
⋮
[6.199971749498808, 5.934538378570725, 1.4279016258909087]
[6.118507632294921, 5.922547039758734, 1.4400424406486527]
[6.1403728288183, 5.910498404357205, 1.4482635368595815]
[6.090899051488509, 5.915645157925797, 1.42031309029363]
[6.083610977818909, 5.908581405699855, 1.4210441555061646]
[6.038207767404079, 5.924342982410118, 1.4087751339842554]
[6.116548598900288, 5.988366089964736, 1.4232171432985437]
[6.088443236372649, 5.99575604362717, 1.4106147809411043]
[6.125540018457247, 5.99712313143013, 1.3984809646389746]