Skip to content

Commit 4cd7d1b

Browse files
Fix and update documentation for v9
1 parent eaecbe3 commit 4cd7d1b

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

docs/src/basics/Composition.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ of `decay2` is the value of the unknown variable `x`.
1616

1717
```@example composition
1818
using ModelingToolkit
19+
using ModelingToolkit: t_nounits as t, D_nounits as D
1920
2021
function decay(; name)
21-
@parameters t a
22+
@parameters a
2223
@variables x(t) f(t)
2324
D = Differential(t)
2425
ODESystem([
2526
D(x) ~ -a * x + f
26-
];
27+
], t;
2728
name = name)
2829
end
2930
3031
@named decay1 = decay()
3132
@named decay2 = decay()
3233
33-
@parameters t
3434
D = Differential(t)
3535
connected = compose(
3636
ODESystem([decay2.f ~ decay1.x
@@ -137,7 +137,7 @@ sys.y = u * 1.1
137137
In a hierarchical system, variables of the subsystem get namespaced by the name of the system they are in. This prevents naming clashes, but also enforces that every unknown and parameter is local to the subsystem it is used in. In some cases it might be desirable to have variables and parameters that are shared between subsystems, or even global. This can be accomplished as follows.
138138

139139
```julia
140-
@parameters t a b c d e f
140+
@parameters a b c d e f
141141

142142
# a is a local variable
143143
b = ParentScope(b) # b is a variable that belongs to one level up in the hierarchy
@@ -197,19 +197,16 @@ higher level system:
197197

198198
```@example compose
199199
using ModelingToolkit, OrdinaryDiffEq, Plots
200+
using ModelingToolkit: t_nounits as t, D_nounits as D
200201
201202
## Library code
202-
203-
@parameters t
204-
D = Differential(t)
205-
206203
@variables S(t), I(t), R(t)
207204
N = S + I + R
208205
@parameters β, γ
209206
210-
@named seqn = ODESystem([D(S) ~ -β * S * I / N])
211-
@named ieqn = ODESystem([D(I) ~ β * S * I / N - γ * I])
212-
@named reqn = ODESystem([D(R) ~ γ * I])
207+
@named seqn = ODESystem([D(S) ~ -β * S * I / N], t)
208+
@named ieqn = ODESystem([D(I) ~ β * S * I / N - γ * I], t)
209+
@named reqn = ODESystem([D(R) ~ γ * I],t )
213210
214211
sir = compose(
215212
ODESystem(

0 commit comments

Comments
 (0)