Skip to content

Commit 649d6a0

Browse files
the examples are real now!
1 parent 0e3f838 commit 649d6a0

File tree

3 files changed

+28
-21
lines changed

3 files changed

+28
-21
lines changed

docs/src/basics/Composition.md

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ equations(connected)
4848
simplified_sys = structural_simplify(connected)
4949

5050
equations(simplified_sys)
51+
52+
#3-element Vector{Equation}:
53+
# Differential(t)(decay1₊f(t)) ~ 0
54+
# Differential(t)(decay1₊x(t)) ~ decay1₊f(t) - (decay1₊a*(decay1₊x(t)))
55+
# Differential(t)(decay2₊x(t)) ~ decay1₊x(t) - (decay2₊a*(decay2₊x(t)))
5156
```
5257

5358
Now we can solve the system:
@@ -64,8 +69,9 @@ p = [
6469
]
6570

6671
using DifferentialEquations
67-
prob = ODEProblem(reduced_system, x0, (0.0, 100.0), p)
72+
prob = ODEProblem(simplified_sys, x0, (0.0, 100.0), p)
6873
sol = solve(prob, Tsit5())
74+
sol[decay2.f]
6975
```
7076

7177
## Basics of Model Composition
@@ -159,7 +165,7 @@ N = S + I + R
159165
seqn.I ~ ieqn.I,
160166
seqn.R ~ reqn.R,
161167
ieqn.R ~ reqn.R,
162-
reqn.I ~ ieqn.I], t, [S,I,R], [β,γ], name=:sir,
168+
reqn.I ~ ieqn.I], t, [S,I,R], [β,γ],
163169
systems=[seqn,ieqn,reqn],
164170
default_p = [
165171
seqn.β => β
@@ -177,27 +183,28 @@ specifying the values at the highest level:
177183
```julia
178184
sireqn_simple = structural_simplify(sir)
179185

186+
equations(sireqn_simple)
187+
188+
# 3-element Vector{Equation}:
189+
#Differential(t)(seqn₊S(t)) ~ -seqn₊β*ieqn₊I(t)*seqn₊S(t)*(((ieqn₊I(t)) + (reqn₊R(t)) + (seqn₊S(t)))^-1)
190+
#Differential(t)(ieqn₊I(t)) ~ ieqn₊β*ieqn₊I(t)*seqn₊S(t)*(((ieqn₊I(t)) + (reqn₊R(t)) + (seqn₊S(t)))^-1) - (ieqn₊γ*(ieqn₊I(t)))
191+
#Differential(t)(reqn₊R(t)) ~ reqn₊γ*ieqn₊I(t)
192+
180193
## User Code
181194

182-
u0 = [sir.S => 990.0,
183-
sir.I => 10.0,
184-
sir.R => 0.0]
195+
u0 = [seqn.S => 990.0,
196+
ieqn.I => 10.0,
197+
reqn.R => 0.0]
185198

186199
p = [
187-
sir.β => 0.5
188-
sir.γ => 0.25
200+
β => 0.5
201+
γ => 0.25
189202
]
190203

191-
# Time span
192204
tspan = (0.0,40.0)
193-
194-
# Define problem
195205
prob = ODEProblem(sireqn_simple,u0,tspan,p,jac=true)
196-
197-
# Solve
198206
sol = solve(prob,Tsit5())
199-
200-
sol[R]
207+
sol[reqn.R]
201208
```
202209

203210
However, one can similarly simplify this process of inheritance by

docs/src/tutorials/nonlinear.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,4 @@ generate the function, i.e.:
104104
nlsys_func = generate_function(ns, [x,y,z], [σ,ρ,β], expression=Val{false})[2]
105105
```
106106

107-
which uses GeneralizedGenerated.jl to build the same world-age function on the fly without eval.
107+
which uses RuntimeGeneratedFunctions.jl to build the same world-age function on the fly without eval.

docs/src/tutorials/ode_modeling.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ eqs = [D(x) ~ σ*(y-x),
1515
D(y) ~ x*-z)-y,
1616
D(z) ~ x*y - β*z]
1717

18-
lorenz1 = ODESystem(eqs,name=:lorenz1)
19-
lorenz2 = ODESystem(eqs,name=:lorenz2)
18+
@named lorenz1 = ODESystem(eqs)
19+
@named lorenz2 = ODESystem(eqs)
2020

2121
@variables a
2222
@parameters γ
2323
connections = [0 ~ lorenz1.x + lorenz2.y + a*γ]
24-
connected = ODESystem(connections,t,[a],[γ],systems=[lorenz1,lorenz2])
24+
@named connected = ODESystem(connections,t,[a],[γ],systems=[lorenz1,lorenz2])
2525

2626
u0 = [lorenz1.x => 1.0,
2727
lorenz1.y => 0.0,
@@ -110,8 +110,8 @@ Let's define two interacting Lorenz equations. To do this, we will
110110
build two `ODESystem`s from the equations we used in the first part:
111111

112112
```julia
113-
lorenz1 = ODESystem(eqs,name=:lorenz1)
114-
lorenz2 = ODESystem(eqs,name=:lorenz2)
113+
@named lorenz1 = ODESystem(eqs)
114+
@named lorenz2 = ODESystem(eqs)
115115
```
116116

117117
Now let's define an interconnection between these ODE systems. Here
@@ -122,7 +122,7 @@ between these two models:
122122
@variables a(t)
123123
@parameters γ
124124
connections = [0 ~ lorenz1.x + lorenz2.y + a*γ]
125-
connected = ODESystem(connections,t,[a],[γ],systems=[lorenz1,lorenz2])
125+
@named connected = ODESystem(connections,t,[a],[γ],systems=[lorenz1,lorenz2])
126126
```
127127

128128
This `ODESystem` thus connects the two Lorenz systems and defines the

0 commit comments

Comments
 (0)