Hi,
I’ve come across Chris Rackauckas post that it is possible to simulate DDEs using Modeling Toolkit (ModelingToolkit: (Transport) delay? Example: Inflow to one water reservoir is a delayed outflow from another - #7 by filip.cerny).
Then I tried to simulate SDDE, and it worked, but the solution looked different from the solution when directly using the DifferentialEquations module. Have I made some mistake or is SDDEProblem not yet compatible with ModelingToolkit?
Thank you! I have attached the simplified code below.
Simulating with MTK:
using DifferentialEquations
using StochasticDelayDiffEq
using ModelingToolkit
using ModelingToolkit: t_nounits as t, D_nounits as D
using Random
using Plots
Random.seed!(1)
@parameters a b τ
@variables x₁(t) x₂(..)
@brownian w₁
eqs = [D(x₁) ~ a * x₁ - x₁ * x₂(t-τ) + 0.2*w₁,
D(x₂(t)) ~ b * x₂(t) + x₁ * x₂(t)]
# Parameters and setup
params = [a => 1., b => -3.0, τ => 0.01]
inits = [x₁ => 1.0, x₂(t) => 1.0]
tspan = (0.0, 20.0)
sys = structural_simplify(System(eqs, t; name=Symbol("LotkaVolterra")))
prob = SDDEProblem(sys, inits, tspan, params; constant_lags=[τ])
sol = solve(prob, SRIW1())
plot(sol, xlims=(0, 20), ylims=(0, 10))
Output:
Simulating with differentialEquations:
using DifferentialEquations
using Plots
using StochasticDelayDiffEq
using StochasticDiffEq
using Random
Random.seed!(1)
function eq!(du, u, h, p, t)
a, b, τ = p
hu2 = h(p, t - τ)[2]
du[1] = a * u[1] - u[1] * hu2
du[2] = b * u[2] + u[1] * u[2] # + h(p, t - τ)[1] # -3 * Vex + Ve * Vex
end
function noise!(du, u, h, p, t)
du1 = 0.2
du2 = 0.
du.= [du1, du2]
end
# Parameters and setup
a, b, τ = 1.0, -3.0, 0.01
params = [a, b, τ]
inits = [1.0, 1.0]
tspan = (0.0, 20.0)
h(p, t) = inits
prob = SDDEProblem(eq!, noise!, inits, h, tspan, params; constant_lags=τ)
sol = solve(prob, SRIW1())
plot(sol, xlims=(0, 20), ylims=(0, 10))
Output: