@@ -47,7 +47,7 @@ eqs = [
47
47
scalarize(D.(mass.v) .~ spring_force(spring) / mass.m .+ g)
48
48
]
49
49
50
- @named _model = ODESystem(eqs, t)
50
+ @named _model = ODESystem(eqs, t, [spring.x; spring.dir; mass.pos], [] )
51
51
@named model = compose(_model, mass, spring)
52
52
sys = structural_simplify(model)
53
53
@@ -132,8 +132,8 @@ eqs = [
132
132
133
133
Finally, we can build the model using these equations and components.
134
134
135
- ``` @example component
136
- @named _model = ODESystem(eqs, t)
135
+ ``` julia
136
+ @named _model = ODESystem (eqs, t, [spring . x; spring . dir; mass . pos], [] )
137
137
@named model = compose (_model, mass, spring)
138
138
```
139
139
@@ -162,9 +162,28 @@ This system can be solved directly as a DAE using [one of the DAE solvers from D
162
162
``` @example component
163
163
sys = structural_simplify(model)
164
164
equations(sys)
165
+
166
+ 4-element Vector{Equation}:
167
+ Differential(t)(mass₊v[1](t)) ~ (-spring₊k*(spring₊x(t) - spring₊l)*mass₊pos[1](t)) / (mass₊m*spring₊x(t))
168
+ Differential(t)(mass₊v[2](t)) ~ (-spring₊k*(spring₊x(t) - spring₊l)*mass₊pos[2](t)) / (mass₊m*spring₊x(t)) - 9.81
169
+ Differential(t)(mass₊pos[1](t)) ~ mass₊v[1](t)
170
+ Differential(t)(mass₊pos[2](t)) ~ mass₊v[2](t)
171
+ ```
172
+
173
+ We are left with only 4 equations involving 4 state variables (` mass.pos[1] ` ,
174
+ ` mass.pos[2] ` , ` mass.v[1] ` , ` mass.v[2] ` ). We can solve the system by converting
175
+ it to an ` ODEProblem ` . Some observed variables are not expanded by default. To
176
+ view the complete equations, one can do
177
+ ``` julia
178
+ julia> full_equations (sys)
179
+ 4 - element Vector{Equation}:
180
+ Differential (t)(mass₊v[1 ](t)) ~ (- spring₊k* (sqrt (abs2 (mass₊pos[1 ](t)) + abs2 (mass₊pos[2 ](t))) - spring₊l)* mass₊pos[1 ](t)) / (mass₊m* sqrt (abs2 (mass₊pos[1 ](t)) + abs2 (mass₊pos[2 ](t))))
181
+ Differential (t)(mass₊v[2 ](t)) ~ (- spring₊k* (sqrt (abs2 (mass₊pos[1 ](t)) + abs2 (mass₊pos[2 ](t))) - spring₊l)* mass₊pos[2 ](t)) / (mass₊m* sqrt (abs2 (mass₊pos[1 ](t)) + abs2 (mass₊pos[2 ](t)))) - 9.81
182
+ Differential (t)(mass₊pos[1 ](t)) ~ mass₊v[1 ](t)
183
+ Differential (t)(mass₊pos[2 ](t)) ~ mass₊v[2 ](t)
165
184
```
166
185
167
- We are left with only 4 equations involving 4 state variables ( ` mass.pos[1] ` , ` mass.pos[2] ` , ` mass.v[1] ` , ` mass.v[2] ` ). We can solve the system by converting it to an ` ODEProblem ` in mass matrix form and solving with an [ ` ODEProblem ` mass matrix solver ] ( https://diffeq.sciml.ai/stable/solvers/dae_solve/#OrdinaryDiffEq.jl-(Mass-Matrix) ) . This is done as follows:
186
+ This is done as follows:
168
187
169
188
``` @example component
170
189
prob = ODEProblem(sys, [], (0., 3.))
0 commit comments