Skip to content

Commit 4d625c8

Browse files
Merge pull request #1610 from ArnoStrouwen/tut1
Small changes to "Composing Ordinary Differential Equations" documentation
2 parents 477f461 + 51ede13 commit 4d625c8

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

docs/src/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ a standard library of prebuilt components for the ModelingToolkit ecosystem.
9191
Hepatology, Immunology, Ion Transport, Mechanical Constitutive Laws,
9292
Metabolism, Myofilament Mechanics, Neurobiology, pH Regulation, PKPD,
9393
Protein Modules, Signal Transduction, and Synthetic Biology.
94-
- [SBMLToolkit.jl](https://github.com/SciML/SBMLToolkit.jl): Import [SBML](http://sbml.org/Main_Page) models into ModelingToolkit
94+
- [SBMLToolkit.jl](https://github.com/SciML/SBMLToolkit.jl): Import [SBML](http://sbml.org/) models into ModelingToolkit
9595
- Uses the robust libsbml library for parsing and transforming the SBML
9696
- [ReactionNetworkImporters.jl](https://github.com/SciML/ReactionNetworkImporters.jl): Import various models into ModelingToolkit
9797
- Supports the BioNetGen `.net` file

docs/src/tutorials/ode_modeling.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,17 @@ using ModelingToolkit
1818
D = Differential(t) # define an operator for the differentiation w.r.t. time
1919

2020
# your first ODE, consisting of a single equation, indicated by ~
21-
@named fol_separate = ODESystem([ RHS ~ (1 - x)/τ,
22-
D(x) ~ RHS ])
21+
@named fol = ODESystem([ D(x) ~ (1 - x)/τ])
2322

2423
using DifferentialEquations: solve
2524
using Plots: plot
2625

27-
prob = ODEProblem(structural_simplify(fol_separate), [x => 0.0], (0.0,10.0), [τ => 3.0])
26+
prob = ODEProblem(fol, [x => 0.0], (0.0,10.0), [τ => 3.0])
2827
sol = solve(prob)
29-
plot(sol, vars=[x,RHS])
28+
plot(sol)
3029
```
3130

32-
![Simulation result of first-order lag element, with right-hand side](https://user-images.githubusercontent.com/13935112/111958403-7e8d3e00-8aed-11eb-9d18-08b5180a59f9.png)
33-
31+
![Simulation result of first-order lag element, with right-hand side](https://user-images.githubusercontent.com/13935112/111958369-703f2200-8aed-11eb-8bb4-0abe9652e850.png)
3432
Now let's start digging into MTK!
3533

3634
## Your very first ODE
@@ -203,6 +201,7 @@ but allows for customization:
203201
@named fol_2 = fol_factory(true) # has observable RHS
204202
```
205203

204+
The `@named` macro rewrites `fol_2 = fol_factory(true)` into `fol_2 = fol_factory(true,:fol_2)`.
206205
Now, these two components can be used as subsystems of a parent system, i.e.
207206
one level higher in the model hierarchy. The connections between the components
208207
again are just algebraic relations:
@@ -218,7 +217,7 @@ connected = compose(ODESystem(connections,name=:connected), fol_1, fol_2)
218217
# fol_2₊f(t)
219218
# fol_1₊x(t)
220219
# fol_2₊x(t)
221-
#
220+
# fol_2₊RHS(t)
222221
# Parameters (2):
223222
# fol_1₊τ
224223
# fol_2₊τ
@@ -247,14 +246,14 @@ connected_simp = structural_simplify(connected)
247246
# [1, 3] = ×
248247
# [2, 4] = ×
249248

250-
equations(connected_simp)
249+
full_equations(connected_simp)
251250
# 2-element Array{Equation,1}:
252251
# Differential(t)(fol_1₊x(t)) ~ (fol_1₊τ^-1)*(1.5 - fol_1₊x(t))
253252
# Differential(t)(fol_2₊x(t)) ~ (fol_2₊τ^-1)*(fol_1₊x(t) - fol_2₊x(t))
254253
```
255-
256254
As expected, only the two state-derivative equations remain,
257255
as if you had manually eliminated as many variables as possible from the equations.
256+
Some observed variables are not expanded unless `full_equations` is used.
258257
As mentioned above, the hierarchical structure is preserved though. So the
259258
initial state and the parameter values can be specified accordingly when
260259
building the `ODEProblem`:
@@ -350,7 +349,7 @@ Here are some notes that may be helpful during your initial steps with MTK:
350349
Where to go next?
351350

352351
* Not sure how MTK relates to similar tools and packages? Read
353-
[Comparison of ModelingToolkit vs Equation-Based Modeling Languages](@ref).
352+
[Comparison of ModelingToolkit vs Equation-Based and Block Modeling Languages](@ref).
354353
* Depending on what you want to do with MTK, have a look at some of the other
355354
**Symbolic Modeling Tutorials**.
356355
* If you want to automatically convert an existing function to a symbolic

0 commit comments

Comments
 (0)