15
15
@constants h = 1
16
16
@variables S(t) I(t) R(t)
17
17
k = 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)
20
21
21
22
# 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]
25
26
@mtkbuild sys = DiscreteSystem(eqs, t)
26
27
27
28
u0 = [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)
31
32
sol = solve(prob, FunctionMap())
32
33
```
33
34
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:
37
39
38
40
``` @example discrete
39
41
@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)
41
43
```
42
44
43
45
Note that the default value is treated as the initial value of ` x(k-1) ` . The value for
0 commit comments