Skip to content

Commit 52c7862

Browse files
authored
Merge branch 'master' into fb/builddocs
2 parents 732c50d + 02ac87f commit 52c7862

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

docs/src/tutorials/spring_mass.md

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ eqs = [
4747
scalarize(D.(mass.v) .~ spring_force(spring) / mass.m .+ g)
4848
]
4949
50-
@named _model = ODESystem(eqs, t)
50+
@named _model = ODESystem(eqs, t, [spring.x; spring.dir; mass.pos], [])
5151
@named model = compose(_model, mass, spring)
5252
sys = structural_simplify(model)
5353
@@ -132,8 +132,8 @@ eqs = [
132132

133133
Finally, we can build the model using these equations and components.
134134

135-
```@example component
136-
@named _model = ODESystem(eqs, t)
135+
```julia
136+
@named _model = ODESystem(eqs, t, [spring.x; spring.dir; mass.pos], [])
137137
@named model = compose(_model, mass, spring)
138138
```
139139

@@ -162,9 +162,28 @@ This system can be solved directly as a DAE using [one of the DAE solvers from D
162162
```@example component
163163
sys = structural_simplify(model)
164164
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)
165184
```
166185

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:
168187

169188
```@example component
170189
prob = ODEProblem(sys, [], (0., 3.))

0 commit comments

Comments
 (0)