Skip to content

Commit dc14e6f

Browse files
finalize comments
1 parent 5a9641c commit dc14e6f

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

docs/src/tutorials/ode_modeling.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,8 @@ D = Differential(t) # define an operator for the differentiation w.r.t. time
3737
```
3838

3939
Note that equations in MTK use the tilde character (`~`) as equality sign.
40-
The `@named` macro just adds the keyword-argument `name` to the call of
41-
`ODESystem`. Its value is the name of the variable the system is assigned to.
42-
For this example, calling `fol_model = ODESystem(...; name=:fol_model)` would do
43-
exactly the same.
40+
Also note that the `@named` macro simply ensures that the symbolic name
41+
matches the name in the REPL. If omitted, you can directly set the `name` keyword.
4442

4543
After construction of the ODE, you can solve it using [DifferentialEquations.jl](https://diffeq.sciml.ai/):
4644

@@ -107,6 +105,10 @@ plot(sol, vars=[x, RHS])
107105

108106
![Simulation result of first-order lag element, with right-hand side](https://user-images.githubusercontent.com/13935112/111958403-7e8d3e00-8aed-11eb-9d18-08b5180a59f9.png)
109107

108+
Note that similarly the indexing of the solution works via the names, and so
109+
`sol[x]` gives the timeseries for `x`, `sol[x,2:10]` gives the 2nd through 10th
110+
values of `x` matching `sol.t`, etc. Note that this works even for variables
111+
which have been eliminated, and thus `sol[RHS]` retrieves the values of `RHS`.
110112

111113
## Specifying a time-variable forcing function
112114
What if the forcing function (the "external input") ``f(t)`` is not constant?
@@ -133,18 +135,15 @@ f_fun(t) = t >= 10 ? value_vector[end] : value_vector[Int(floor(t))+1]
133135
@named fol_external_f = ODESystem([f ~ f_fun(t), D(x) ~ (f - x)/τ])
134136
prob = ODEProblem(structural_simplify(fol_external_f), [x => 0.0], (0.0,10.0), [τ => 0.75])
135137

136-
using DifferentialEquations: Rodas4
137-
sol = solve(prob, Rodas4())
138+
sol = solve(prob)
138139
plot(sol, vars=[x,f])
139140
```
140141

141142
![Simulation result of first-order lag element, step-wise forcing function](https://user-images.githubusercontent.com/13935112/111958424-83ea8880-8aed-11eb-8f42-489f4b44c3bc.png)
142143

143144

144-
Note that for this problem, the implicit solver `Rodas4` is used, to cleanly resolve
145-
the steps in the forcing function.
146-
147145
## Building component-based, hierarchical models
146+
148147
Working with simple one-equation systems is already fun, but composing more complex systems from
149148
simple ones is even more fun. Best practice for such a "modeling framework" could be to use
150149

@@ -275,6 +274,7 @@ partial derivatives, are not used. Let's benchmark this (`prob` still is the pro
275274

276275
```julia
277276
using BenchmarkTools
277+
using DifferentialEquations: Rodas4
278278

279279
@btime solve(prob, Rodas4());
280280
# 251.300 μs (873 allocations: 31.18 KiB)
@@ -293,7 +293,9 @@ prob_an = ODEProblem(connected_simp, u0, (0.0,10.0), p; jac=true, sparse=true)
293293
The speedup is significant. For this small dense model (3 of 4 entries are populated), using sparse matrices is counterproductive in terms of required memory allocations. For large,
294294

295295
hierarchically built models, which tend to be sparse, speedup and the reduction of
296-
memory allocation can be expected to be substantial.
296+
memory allocation can be expected to be substantial. In addition, these problem
297+
builders allow for automatic parallelism using the structural information. For
298+
more information, see the [ODESystem](@ref ODESystem) page.
297299

298300
## Notes and pointers how to go on
299301
Here are some notes that may be helpful during your initial steps with MTK:

0 commit comments

Comments
 (0)