I recently started with Julia and wanted to implement one of my usual problems - implement time-depended events.
For now I have:
# Packages using Plots using DifferentialEquations # Parameters k21 = 0.14*24 k12 = 0.06*24 ke = 1.14*24 α = 0.5 β = 0.05 η = 0.477 μ = 0.218 k1 = 0.5 V1 = 6 # Time maxtime = 10 tspan = (0.0, maxtime) # Dose stim = 100 # Initial conditions x0 = [0 0 2e11 8e11] # Model equations function system(dy, y, p, t) dy = k21*y - (k12 + ke)*y dy = k12*y - k21*y dy = (α - μ - η)*y + β*y - k1/V1*y*y dy = μ*y - β*y end # Events eventtimes = [2, 5] function condition(y, t, integrator) t - eventtimes end function affect!(integrator) x0 = stim end cb = ContinuousCallback(condition, affect!) # Solve prob = ODEProblem(system, x0, tspan) sol = solve(prob, Rodas4(), callback = cb) # Plotting plot(sol, layout = (2, 2))
But the output that is give is not correct. More specifically, the events are not taken into account and the initial condition doesn’t seems to be
Any help would be greatly appreciated.