@@ -278,7 +278,7 @@ initsys = prob2.f.initializeprob.f.sys
278278
279279The system is fully determined, and the equations are solvable.
280280
281- ``` @example
281+ ``` @example paraminit
282282[equations(initsys); observed(initsys)]
283283```
284284
@@ -464,56 +464,3 @@ sol[α * x - β * x * y]
464464``` @example init
465465plot(sol)
466466```
467-
468- ## Solving for parameters during initialization
469-
470- Sometimes, it is necessary to solve for a parameter during initialization. For example,
471- given a spring-mass system we want to find the un-stretched length of the spring given
472- that the initial condition of the system is its steady state.
473-
474- ``` @example init
475- using ModelingToolkitStandardLibrary.Mechanical.TranslationalModelica: Fixed, Mass, Spring,
476- Force, Damper
477- using ModelingToolkitStandardLibrary.Blocks: Constant
478-
479- @named mass = Mass(; m = 1.0, s = 1.0, v = 0.0, a = 0.0)
480- @named fixed = Fixed(; s0 = 0.0)
481- @named spring = Spring(; c = 2.0, s_rel0 = missing)
482- @named gravity = Force()
483- @named constant = Constant(; k = 9.81)
484- @named damper = Damper(; d = 0.1)
485- @mtkbuild sys = ODESystem(
486- [connect(fixed.flange, spring.flange_a), connect(spring.flange_b, mass.flange_a),
487- connect(mass.flange_a, gravity.flange), connect(constant.output, gravity.f),
488- connect(fixed.flange, damper.flange_a), connect(damper.flange_b, mass.flange_a)],
489- t;
490- systems = [fixed, spring, mass, gravity, constant, damper],
491- guesses = [spring.s_rel0 => 1.0])
492- ```
493-
494- Note that we explicitly provide ` s_rel0 = missing ` to the spring. Parameters are only
495- solved for during initialization if their value (either default, or explicitly passed
496- to the ` ODEProblem ` constructor) is ` missing ` . We also need to provide a guess for the
497- parameter.
498-
499- If a parameter is not given a value of ` missing ` , and does not have a default or initial
500- value, the ` ODEProblem ` constructor will throw an error. If the parameter _ does_ have a
501- value of ` missing ` , it must be given a guess.
502-
503- ``` @example init
504- prob = ODEProblem(sys, [], (0.0, 1.0))
505- prob.ps[spring.s_rel0]
506- ```
507-
508- Note that the value of the parameter in the problem is zero, similar to unknowns that
509- are solved for during initialization.
510-
511- ``` @example init
512- integ = init(prob)
513- integ.ps[spring.s_rel0]
514- ```
515-
516- The un-stretched length of the spring is now correctly calculated. The same result can be
517- achieved if ` s_rel0 = missing ` is omitted when constructing ` spring ` , and instead
518- ` spring.s_rel0 => missing ` is passed to the ` ODEProblem ` constructor along with values
519- of other parameters.
0 commit comments