Solving Differential Equation with Delay

Hi,
I have an ODE problem to which I need to apply delay . But trying to solve as per the documentation of delay differential equations doesn’t seem to work for me…Can someone please lend a hand?

Here is the ODE Problem I have, that induces a step response in variable u1, and correspondingly have changes in x1.

@parameters t, c0
D= Differential(t)
@variables  x1(t), u1(t)

# input varying- u1
value_vector=[88.05,98.5]
fun(t) = t >= 400 ? value_vector[end] : value_vector[1]
@register fun(t)

eqs = [
u1     ~  fun(t),
D(x1) ~ (-x1+u1)/c0 
 ]
 
@named sys =  ODESystem(eqs)
simplified_sys=structural_simplify(sys)

x0=[ x1 => 88.05]
p=[c0=> 10.0  ]    

prob = ODEProblem(simplified_sys,x0,(0.0,1000.0),p)


sol = solve(prob)
plot(sol)

Now how can I introduce a dead time in my differential equation, such that the response of x1 shall be delayed for 100 seconds after the step change I have induced in u1 after 400 sec as above? Mathematically I guess it would be something like,

D(x1) = (-x1 + u1(t - tau)) / c0 , where deadtime tau= 100

Can this be done with delay differential equations setup in DifferentialEquations.jl? Any help is highly appreciated and thanks in advance…

Here are my package specifications:
Julia Version 1.8.5
[a134a8b2] BlackBoxOptim v0.6.2
[336ed68f] CSV v0.10.10
[a93c6f00] DataFrames v1.5.0
[bcd4f6db] DelayDiffEq v5.42.0
[1130ab10] DiffEqParamEstim v2.0.1
[0c46a032] DifferentialEquations v7.7.0
[f6369f11] ForwardDiff v0.10.35
[961ee093] ModelingToolkit v8.55.0
[7f7a1694] Optimization v3.14.0
[3e6eede4] OptimizationBBO v0.1.4
[36348300] OptimizationOptimJL v0.1.8
[91a5bcdd] Plots v1.38.10
[731186ca] RecursiveArrayTools v2.38.3
[24249f21] SymPy v1.1.9

Yes, it can be done with DifferentialEquations.jl, but that’s not what you’re showing here. You’re using ModelingToolkit.jl, a symbolic DSL for DifferentialEquations.jl. This currently does not support delay differential equations, though it is something both in progress and with prototypes.

For now, I’d recommend directly targeting DifferentialEquations.jl if this is what you need. Examples can be found in the documentation:

If this system is representative of what you are actually doing, you can use the ControlSystems interface to the delay modeling in DifferentialEquations.jl:

using ControlSystems, Plots
c0 = 10.0
sys = tf(1, [c0, 1]) |> ss
delaysys = sys*delay(100)
input = (x, t)->t>=400 ? [98.5] : [88.05]
x0 = [88.05/sys.C[]]
sol = lsim(delaysys, input, 0:0.1:1000, x0)
plot(sol)

Please note: this assumes that the input is zero before t = 0.