The issue is that you used the argument callbacks
instead of callback
. That was my bad (and we really need to error for that). A corrected code is:
using DifferentialEquations
f = @ode_def_bare ManagedLinear begin
dBB = r*(1- BB/K)*BB -xI*yIB*BI*((BB^h/(B0^h + BB^h))/eIB)
dBI = -xI*BI + xI*yIB*BI*(BB^h/(B0^h + BB^h))-xT *yTI*BT*((BI^h/(B0^h + BI^h))/eTI)
dBT = -xT*BT + xT*yTI*BT*(BI^h/(B0^h + BI^h))-q*BT*E + f1 + f2
end K r yIB yTI eIB eTI B0 h xI xT q E f1 f2
function condition(u,t,integrator)
t == 200.
end
function affect!(integrator)
integrator.p[13] = 0.01
end
cb = DiscreteCallback(condition, affect!)
function condition2(u,t,integrator)
t == 200.
end
function affect2!(integrator)
integrator.p[14] = 50
end
cb2 = DiscreteCallback(condition2, affect2!)
cbs = CallbackSet(cb,cb2)
u0 = [500.0,200.0,100.0]
tspan = (0.0,1000.0)
p = [450, 1.1, 10, 10, 0.66, 0.85, 80, 1.2, 0.15, 0.06, 0.01, 50, 0, 0] # initial f1 = 0.0 f2 = 0.0
# K r yIB yTI eIB eTI B0 h xI xT q E
prob = ODEProblem(f,u0,tspan,p)
sol=solve(prob,Rosenbrock23(),callback=cbs,tstops=[200.0],reltol=1e-6)
using Plots
plot(sol, title = "Food Chain Managed Linear ", xlabel = "Time" ,ylabel = "Density", lw=0.5)