1515@constants h = 1
1616@variables S(t) I(t) R(t)
1717k = ShiftIndex(t)
18- infection = rate_to_proportion(β * c * I(k-1) / (S(k-1) * h + I(k-1) + R(k-1)), δt * h) * S(k-1)
19- recovery = rate_to_proportion(γ * h, δt) * I(k-1)
18+ infection = rate_to_proportion(
19+ β * c * I(k - 1) / (S(k - 1) * h + I(k - 1) + R(k - 1)), δt * h) * S(k - 1)
20+ recovery = rate_to_proportion(γ * h, δt) * I(k - 1)
2021
2122# Equations
22- eqs = [S(k) ~ S(k- 1) - infection * h,
23- I(k) ~ I(k- 1) + infection - recovery,
24- R(k) ~ R(k- 1) + recovery]
23+ eqs = [S(k) ~ S(k - 1) - infection * h,
24+ I(k) ~ I(k - 1) + infection - recovery,
25+ R(k) ~ R(k - 1) + recovery]
2526@mtkbuild sys = DiscreteSystem(eqs, t)
2627
2728u0 = [S(k - 1) => 990.0, I(k - 1) => 10.0, R(k - 1) => 0.0]
@@ -31,13 +32,14 @@ prob = DiscreteProblem(sys, u0, tspan, p)
3132sol = solve(prob, FunctionMap())
3233```
3334
34- All shifts must be negative. If default values are provided, they are treated as the value
35- for the variable at the previous timestep. For example, consider the following system to
36- generate the Fibonacci series:
35+ All shifts must be non-positive, i.e., discrete-time variables may only be indexed at index
36+ ` k, k-1, k-2, ... ` . If default values are provided, they are treated as the value of the
37+ variable at the previous timestep. For example, consider the following system to generate
38+ the Fibonacci series:
3739
3840``` @example discrete
3941@variables x(t) = 1.0
40- @mtkbuild sys = DiscreteSystem([x ~ x(k- 1) + x(k- 2)], t)
42+ @mtkbuild sys = DiscreteSystem([x ~ x(k - 1) + x(k - 2)], t)
4143```
4244
4345Note that the default value is treated as the initial value of ` x(k-1) ` . The value for
0 commit comments