|
1 |
| -# Getting Started with ModelingToolkit.jl |
| 1 | +# [Getting Started with ModelingToolkit.jl](@id getting_started) |
2 | 2 |
|
3 | 3 | This is an introductory tutorial for ModelingToolkit (MTK). We will demonstrate
|
4 | 4 | the basics of the package by demonstrating how to define and simulate simple
|
@@ -97,6 +97,33 @@ plot(solve(prob))
|
97 | 97 | The parameter values are determined using the right hand side of the expressions in the `@parameters` block,
|
98 | 98 | and similarly initial conditions are determined using the right hand side of the expressions in the `@variables` block.
|
99 | 99 |
|
| 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 | + |
100 | 127 | ## Algebraic relations and structural simplification
|
101 | 128 |
|
102 | 129 | You could separate the calculation of the right-hand side, by introducing an
|
|
0 commit comments