How to model a chemical reaction network with changing parameters? (Catalyst.jl)

And here is a version that uses IfElse.ifelse, and so probably works better in applications that might need AD:

using Catalyst, OrdinaryDiffEq, Plots, IfElse

rate(k1,k2,tswitch,t) = IfElse.ifelse(t < tswitch, k1, k2)

rn = @reaction_network begin
       rate(k1,k2,tswitch,t), A --> 0
       end k1 k2 tswitch
p = (:k1 => 0.0, :k2 => 1.0, :tswitch => 1.0)
u0 = [:A => 10.0]
tspan = (0.0,3.0)
oprob = ODEProblem(rn,u0,tspan,p)
sol = solve(oprob, Tsit5(), tstops=[1.0])
plot(sol)
1 Like