Skip to content

Commit a8b341f

Browse files
committed
add section about different par and ini values in getting started doc
1 parent 3c9de53 commit a8b341f

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

docs/src/tutorials/ode_modeling.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Getting Started with ModelingToolkit.jl
1+
# [Getting Started with ModelingToolkit.jl](@id getting_started)
22

33
This is an introductory tutorial for ModelingToolkit (MTK). We will demonstrate
44
the basics of the package by demonstrating how to define and simulate simple
@@ -97,6 +97,33 @@ plot(solve(prob))
9797
The parameter values are determined using the right hand side of the expressions in the `@parameters` block,
9898
and similarly initial conditions are determined using the right hand side of the expressions in the `@variables` block.
9999

100+
## Using different values for parameters and initial conditions
101+
102+
If you want to simulate the same model,
103+
but with different values for the parameters and initial conditions than the default values,
104+
you likely do not want to write an entirely new `@mtkmodel`.
105+
ModelingToolkit supports overwriting the default values:
106+
107+
```@example ode2
108+
@mtkbuild fol_different_values = FOL(; τ = 1 / 3, x = 0.5)
109+
prob = ODEProblem(fol_different_values, [], (0.0, 10.0), [])
110+
plot(solve(prob))
111+
```
112+
113+
Alternatively, this overwriting could also have occurred at the `ODEProblem` level.
114+
115+
```@example ode2
116+
prob = ODEProblem(fol, [fol.τ => 1 / 3], (0.0, 10.0), [fol.x => 0.5])
117+
plot(solve(prob))
118+
```
119+
120+
Here, the second argument of `ODEProblem` is an array of `Pairs`.
121+
The left hand side of each Pair is the parameter you want to overwrite,
122+
and the right hand side is the value to overwrite it with.
123+
Similarly, the initial conditions are overwritten in the fourth argument.
124+
One important difference with the previous method is
125+
that the parameter has to be referred to as `fol.τ` instead of just `τ`.
126+
100127
## Algebraic relations and structural simplification
101128

102129
You could separate the calculation of the right-hand side, by introducing an

0 commit comments

Comments
 (0)