Fig 1.07#
Collins toggle switch
For Figures 1.7, 7.13, 7.14, 7.15
using OrdinaryDiffEq
using ModelingToolkit
using Plots
Plots.default(linewidth=2)
Convenience functions
hil(x, k) = x / (x + k)
hil(x, k, n) = hil(x^n, k^n)
hil (generic function with 2 methods)
Define the problem
function build_collins(;name)
@parameters begin
a1=3.0
a2=2.5
β=4.0
γ=4.0
end
@independent_variables t
@variables begin
s1(t)=0.075
s2(t)=2.5
i1(t)
i2(t)
end
D = Differential(t)
eqs = [
D(s1) ~ a1 * hil(1 + i2, s2, β) - s1,
D(s2) ~ a2 * hil(1 + i1, s1, γ) - s2,
i2 ~ 10 * (10 < t) * (t < 20),
i1 ~ 10 * (30 < t) * (t < 40),
]
return ODESystem(eqs, t; name)
end
build_collins (generic function with 1 method)
@mtkbuild sys = build_collins()
\[\begin{split} \begin{align}
\frac{\mathrm{d} \mathtt{s1}\left( t \right)}{\mathrm{d}t} &= - \mathtt{s1}\left( t \right) + \frac{\left( 1 + \mathtt{i2}\left( t \right) \right)^{\beta} \mathtt{a1}}{\left( 1 + \mathtt{i2}\left( t \right) \right)^{\beta} + \left( \mathtt{s2}\left( t \right) \right)^{\beta}} \\
\frac{\mathrm{d} \mathtt{s2}\left( t \right)}{\mathrm{d}t} &= \frac{\left( 1 + \mathtt{i1}\left( t \right) \right)^{\gamma} \mathtt{a2}}{\left( \mathtt{s1}\left( t \right) \right)^{\gamma} + \left( 1 + \mathtt{i1}\left( t \right) \right)^{\gamma}} - \mathtt{s2}\left( t \right)
\end{align}
\end{split}\]
Solve the problem
tspan = (0.0, 50.0)
prob = ODEProblem(sys, [], tspan, [])
sol = solve(prob, tstops=10:10:40)
retcode: Success
Interpolation: 3rd order Hermite
t: 51-element Vector{Float64}:
0.0
0.38548049109061366
1.2786313586853497
2.464538731594535
4.06089298356771
6.199065127274195
9.163107137014421
10.0
10.237564173675388
10.345905622741512
⋮
36.914997164885754
37.93079710385752
39.07484274669089
40.0
41.178943649875706
42.81986325559389
44.70418578722446
47.243347624826804
50.0
u: 51-element Vector{Vector{Float64}}:
[0.075, 2.5]
[0.07496310584167311, 2.4999747263084027]
[0.07491895384143081, 2.499943104158718]
[0.07489947360105878, 2.499927975740838]
[0.07489347508722309, 2.4999227222886917]
[0.07489238103870029, 2.499921565722204]
[0.0748923054927769, 2.4999214349680665]
[0.07489223296465887, 2.4999213893330796]
[0.6391346146761681, 2.3721192115081546]
[0.8809050681389734, 2.319140246326736]
⋮
[0.08211174811519016, 2.4974663084645288]
[0.07761093651936421, 2.4990818963098618]
[0.07579211279532862, 2.499707057292954]
[0.07525607577666808, 2.499713078290433]
[0.0750131183637875, 2.4998565770051657]
[0.0749184782720752, 2.499908252504365]
[0.0748968712475701, 2.499919138177413]
[0.07489294615719223, 2.499920936863924]
[0.07489232760866724, 2.499921249118503]
Visual
plot(sol, legend=:right, xlabel = "Time", ylabel="Concentration", title="Fig 1.7")
This notebook was generated using Literate.jl.