I’m playing with the new (at least to me) @mtkmodel
syntax. Here’s my standard SIR model.
using Symbolics
using ModelingToolkit: t_nounits as t, D_nounits as D
using OrdinaryDiffEq
using Plots
@mtkmodel SIR begin
@parameters begin
β
γ
end
@variables begin
S(t)
I(t)
R(t)
end
@equations begin
D(S) ~ -β * S * I
D(I) ~ β * S * I - γ * I
D(R) ~ γ * I
end
end
@mtkbuild sir=SIR()
prob = ODEProblem(sir,
[sir.S => 990.0, sir.I => 10.0, sir.R => 0.0],
(0.0, 40.0),
[sir.β => 0.0005, sir.γ => 0.25])
sol = solve(prob, Tsit5())
plot(sol)
I want to define the model like this:
@equations begin
D(S) ~ -β * S * I/N
D(I) ~ β * S * I/N - γ * I
D(R) ~ γ * I
end
where N=S+I+R
. In the non-DSL version, I just write this:
@variables S(t), I(t), R(t)
N = S + I + R
How do I introduce N into @mtkmodel
?