# Julia DifferentialEquations: add delay into ODE

Hello,
I have a set of ODE to model the growth of bacteria nad phages:

``````function multiInfect!(du, u, p, t)
μ, ν, κ, φ, ψ, ω, β, Β, ρ, τ, η, Η = p
#=
du = resident susceptible
du = resident infected
du = resident phage
=#
TOT = u+u+u+u
du = (μ * u) * (1 - TOT/κ) - (φ * u * u) - (ω * u)
du = (φ * u * u) - (η * u) - (ω * u)
du = (β * η * u) - (ρ * φ * u * u) - (ω * u)

du = (ν * u) * (1 - TOT/κ) - (ψ * u * u) - (ω * u)
du = (ψ * u * u) - (Η * u) - (ω * u)
du = (Β * Η * u) - (ρ * ψ * u * u) - (ω * u)
end

# parameters
mu    = 0.47        # maximum growth rate susceptible (B. longum)
nu    = 0.72        # maximum growth rate resistant (E. coli)
kappa = 2.2*10^7    # maximum population density
phi   = 10.0^-9     # adsorption rate
psi   = 10.0^-9     # adsorption rate alternative
omega = 0.05        # outflow
eta   = 1.0         # lyse rate
Eta   = 1.0         # lyse rate alternative
beta  = 50.0        # burst size
Beta  = 50.0        # burst size alternative
rho   = 0.6         # reinfection rate
tau   = 3.62        # latency time
tmax  = 4000.0      # time span 0-tmax
s0    = 50000.0     # initial susceptible population
i0    = 1.0e-9      # initial infected population
v0    = 80.0        # initial phage population
r_s0    = 50000.0     # initial resident susceptible population
r_i0    = 1.0e-9      # initial resident infected population
r_v0    = 80.0        # initial resident phage population
i_s0    = 500.0       # initial invader susceptible population
i_i0    = 1.0e-9      # initial invader infected population
i_v0    = 80.0        # initial invader phage population
# implement
tspan = (0.0, tmax)
u0 = [r_s0, r_i0, r_v0, i_s0, i_i0, i_v0]
parms = [mu, nu, kappa, phi, psi, omega, beta, Beta, rho, tau, eta, Eta]
prob = ODEProblem(multiInfect!, u0, tspan, parms)
soln = solve(prob, AutoVern7(Rodas5()) )
``````

which gives me this figure

I would like to introduce the invading bacteria after a certain time lag, let’s say 1000 hours, so I added this modificaion:

``````condition(u, t, integrator) = t==1000
affect!(integrator) = integrator.u += i_s0
cb = DiscreteCallback(condition,affect!)
prob = ODEProblem(multiInfect!, u0, tspan, parms)
soln = solve(prob, AutoVern7(Rodas5()), callback=cb, tstops=)
``````

but the solution is the same and it is evident that the invader was present from the beginning.
How can I properly set the delay?
Thank you

You are setting that population to 500 initially in `u0` (so it is not starting at zero), and adding 500 again at `t==1000`, but by then the population appears to be so large that 500 would not make a visible difference (if I’m lining up the state variables to the plot lines correctly).

I see… the initial inoculum must be zero, of course. Thanks.
I changed i_s0 to 1e-9 (I was told it is better to have very small numbers than zero altogether) and

``````condition(u, t, integrator) = t==1000           # time of inoculum
affect!(integrator) = integrator.u += 500    # amount of inoculum
``````

but again the inoculum does not happen at t=1000 but at the beginning:

What am I missing?
Thank you

Actually, if I use zero instead of the suggested `1e-9`, the system works:

I think this solves the problem!
Thank you