You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/tutorial/Modeling.md
+32-17Lines changed: 32 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,25 +25,31 @@ LowPassFilter = Model(
25
25
equations = :[T *der(x) + x = u],
26
26
)
27
27
```
28
-
The symbols `input` and `output` refer to predefined variable constructors to define the input and output variables. If an equation has just a unique variable in the left hand side, `y`, the right hand side can be given as a quoted expression in a Var-constructor `Var(:x)` after the `output` constructor combined with the merge operator, `|`, see below.
28
+
29
+
The symbols `input` and `output` refer to predefined variable constructors to define the input and output variables.
30
+
If an equation has just a unique variable in the left hand side, `y`, the right hand side can be given as a quoted expression in a Var-constructor `Var(:x)` after the `output` constructor combined with the merge operator, `|`, see below.
29
31
30
32
## 2.2 Merging models
31
33
32
-
It is possible to combine models by merging. If we want to change the model to become a highpass filter, an alternative output equation
34
+
It is possible to combine models by merging.
35
+
If we want to change the model to become a high-pass filter, an alternative output equation
33
36
34
37
```math
35
38
y = -x + u
36
39
```
37
40
38
-
is defined in an anonymous model `Model( y = :(-x + u) )`. This anonymous model is merged with `LowPassFilter` using the merge operator `|`:
41
+
is defined in an anonymous model `Model( y = :(-x + u) )`.
42
+
This anonymous model is merged with `LowPassFilter` using the merge operator `|`:
39
43
40
44
```julia
41
45
HighPassFilter = LowPassFilter |Model( y =Var(:(-x + u) ) )
42
46
```
43
47
44
48
The merging implies that the `output` property of `y` is kept, but the binding expression is changed from `:x` to `:(-x + u)`.
45
49
46
-
In general, recursive merging is desired and Modia provides a `mergeModels` function for that (see appendix [A.3 MergeModels algorithm](@ref)). This function is invoked as a binary operator `|` (also used for merge in Python). Note, that the order of the arguments/operands are important.
50
+
In general, recursive merging is desired and Modia provides a `mergeModels` function for that (see appendix [A.3 MergeModels algorithm](@ref)).
51
+
This function is invoked as a binary operator `|` (also used for merge in Python).
52
+
Note, that the order of the arguments/operands are important.
47
53
48
54
Generalizing the block to have two outputs for both low and high pass filtering would be done as follows:
49
55
@@ -108,7 +114,9 @@ LowAndHighPassFilter = Model(
108
114
109
115
## 2.3 Functions and tables
110
116
111
-
In order to test an input/output block as defined in the previous section, an input needs to be defined. This can be made by adding an equation for `u`. Assume we want `u` to be sinousoidial with an increasing frequency:
117
+
In order to test an input/output block as defined in the previous section, an input needs to be defined.
118
+
This can be made by adding an equation for `u`.
119
+
Assume we want `u` to be sinusoidal with an increasing frequency:
`time` is a reserved name for the independent variable. It has unit `s` for seconds. The Julia package [Unitful](https://painterqubits.github.io/Unitful.jl/stable/) provides a means for defining units and managing unit inference. It need not be explicitly defined, because its symbols are exported by `using Modia`. Definition of units is done with a string macro `u"..."`. In this case, the input signal was given unit Volt. The state x must then also have consistent unit, that is Volt. If the model equations contain systems of simultaneous equations, then approximate guess values, optionally with units, must be given `start`: `i = Var(start=0.0u"A")`.
128
+
`time` is a reserved name for the independent variable.
129
+
It has unit `s` for seconds.
130
+
The Julia package [Unitful](https://painterqubits.github.io/Unitful.jl/stable/) provides a means for defining units and managing unit inference.
131
+
It need not be explicitly defined, because its symbols are exported by `using Modia`.
132
+
Definition of units is done with a string macro `u"..."`.
133
+
In this case, the input signal was given unit Volt.
134
+
The state `x` must then also have consistent unit, that is Volt.
135
+
If the model equations contain systems of simultaneous equations, then approximate guess values, optionally with units, must be given `start`: `i = Var(start=0.0u"A")`.
121
136
122
137
The input signal can also be defined by interpolation in a table:
0 commit comments