@@ -95,12 +95,11 @@ rc_eqs = [
95
95
connect (capacitor. n, source. n, ground. g)
96
96
]
97
97
98
- @named rc_model = ODESystem (rc_eqs, t,
99
- systems = [resistor, capacitor, source, ground])
98
+ @named rc_model = compose ( ODESystem (rc_eqs, t) ,
99
+ [resistor, capacitor, source, ground])
100
100
sys = structural_simplify (rc_model)
101
101
u0 = [
102
102
capacitor. v => 0.0
103
- capacitor. p. i => 0.0
104
103
]
105
104
prob = ODAEProblem (sys, u0, (0 , 10.0 ))
106
105
sol = solve (prob, Tsit5 ())
@@ -289,15 +288,15 @@ rc_eqs = [
289
288
Finally we build our four component model with these connection rules:
290
289
291
290
``` julia
292
- @named rc_model = ODESystem (rc_eqs, t,
293
- systems = [resistor, capacitor, source, ground])
291
+ @named rc_model = compose ( ODESystem (rc_eqs, t)
292
+ [resistor, capacitor, source, ground])
294
293
```
295
294
296
- Notice that this model is acasual because we have not specified anything about
297
- the causality of the model. We have simply specified what is true about each
298
- of the variables. This forms a system of differential-algebraic equations
299
- (DAEs) which define the evolution of each state of the system. The
300
- equations are:
295
+ Note that we can also specify the subsystems in a vector. This model is acasual
296
+ because we have not specified anything about the causality of the model. We have
297
+ simply specified what is true about each of the variables. This forms a system
298
+ of differential-algebraic equations (DAEs) which define the evolution of each
299
+ state of the system. The equations are:
301
300
302
301
``` julia
303
302
equations (rc_model)
@@ -369,9 +368,10 @@ parameters(rc_model)
369
368
This system could be solved directly as a DAE using [one of the DAE solvers
370
369
from DifferentialEquations.jl](https://diffeq.sciml.ai/stable/solvers/dae_solve/).
371
370
However, let's take a second to symbolically simplify the system before doing the
372
- solve. The function `structural_simplify` looks for all of the equalities and
373
- eliminates unnecessary variables to build the leanest numerical representation
374
- of the system. Let's see what it does here:
371
+ solve. Although we can use ODE solvers that handles mass matrices to solve the
372
+ above system directly, we want to run the `structural_simplify` function first,
373
+ as it eliminates many unnecessary variables to build the leanest numerical
374
+ representation of the system. Let's see what it does here:
375
375
376
376
``` julia
377
377
sys = structural_simplify (rc_model)
@@ -410,16 +410,13 @@ plot(sol)
410
410
411
411

412
412
413
- However, we can also choose to use the "torn nonlinear system" to remove all
414
- of the algebraic variables from the solution of the system. Note that this
415
- requires having done `structural_simplify`. MTK can numerically solve all
416
- the unreduced algebraic equations numerically. This is done by using
417
- `ODAEProblem` like:
413
+ Since we have run `structural_simplify`, MTK can numerically solve all the
414
+ unreduced algebraic equations numerically using the `ODAEProblem` (note the
415
+ letter `A`):
418
416
419
417
``` julia
420
418
u0 = [
421
419
capacitor. v => 0.0
422
- capacitor. p. i => 0.0
423
420
]
424
421
prob = ODAEProblem (sys, u0, (0 , 10.0 ))
425
422
sol = solve (prob, Rodas4 ())
0 commit comments