Fig 1.07

Fig 1.07#

Collins toggle switch

For Figures 1.7, 7.13, 7.14, 7.15

using DifferentialEquations
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.237564185562528
 10.345905646886505
  ⋮
 36.914994660949574
 37.93079444047982
 39.07483977090036
 40.0
 41.178947000361006
 42.81986852128736
 44.704194706317494
 47.24335988680653
 50.0
u: 51-element Vector{Vector{Float64}}:
 [0.075, 2.5]
 [0.07496310584167311, 2.4999747263084027]
 [0.07491895384143085, 2.499943104158718]
 [0.0748994736010587, 2.499927975740838]
 [0.07489347508722302, 2.4999227222886917]
 [0.07489238103870034, 2.499921565722204]
 [0.07489230549277692, 2.4999214349680665]
 [0.07489223296465884, 2.4999213893330796]
 [0.6391346400308425, 2.3721191827614794]
 [0.8809051168261279, 2.319140205275445]
 ⋮
 [0.08211176550108486, 2.497466302125208]
 [0.07761094350757095, 2.4990818938671304]
 [0.07579211539912203, 2.4997070564231003]
 [0.07525607577887046, 2.4997130777631624]
 [0.07501311800968505, 2.4998565770549246]
 [0.07491847815633552, 2.499908252535931]
 [0.07489687121541065, 2.49991913818762]
 [0.07489294615328414, 2.49992093686432]
 [0.07489232760577462, 2.499921249120588]

Visual

plot(sol, legend=:right, xlabel = "Time", ylabel="Concentration", title="Fig 1.7")
../_images/b94922cdf38d0ac3cb5523de7a19470488fdc9ba539f520cc042545528a7adcb.png

This notebook was generated using Literate.jl.