@@ -19,7 +19,7 @@ x' = f(x,y,t)\\
1919```
2020
2121where `` x `` are the differential variables and `` y `` are the algebraic variables.
22- An initial condition `` u0 = [x(t_0) y(t_0)] `` is said to be consistent if
22+ An initial condition `` u0 = [x(t_0) y(t_0)] `` is said to be consistent if
2323`` g(x(t_0),y(t_0),t_0) = 0 `` .
2424
2525For ODEs, this is trivially satisfied. However, for more complicated systems it may
@@ -64,13 +64,13 @@ This solves via:
6464
6565``` @example init
6666sol = solve(prob, Rodas5P())
67- plot(sol, idxs = (x,y))
67+ plot(sol, idxs = (x, y))
6868```
6969
7070and we can check it satisfies our conditions via:
7171
7272``` @example init
73- conditions = getfield.(equations(pend)[3:end],:rhs)
73+ conditions = getfield.(equations(pend)[3:end], :rhs)
7474```
7575
7676``` @example init
@@ -93,48 +93,50 @@ We can similarly choose `λ = 0` and solve for `y` to start the system:
9393``` @example init
9494prob = ODEProblem(pend, [x => 1, λ => 0], (0.0, 1.5), [g => 1], guesses = [y => 1])
9595sol = solve(prob, Rodas5P())
96- plot(sol, idxs = (x,y))
96+ plot(sol, idxs = (x, y))
9797```
9898
9999or choose to satisfy derivative conditions:
100100
101101``` @example init
102- prob = ODEProblem(pend, [x => 1, D(y) => 0], (0.0, 1.5), [g => 1], guesses = [λ => 0, y => 1])
102+ prob = ODEProblem(
103+ pend, [x => 1, D(y) => 0], (0.0, 1.5), [g => 1], guesses = [λ => 0, y => 1])
103104sol = solve(prob, Rodas5P())
104- plot(sol, idxs = (x,y))
105+ plot(sol, idxs = (x, y))
105106```
106107
107- Notice that since a derivative condition is given, we are required to give a
108+ Notice that since a derivative condition is given, we are required to give a
108109guess for ` y ` .
109110
110111We can also directly give equations to be satisfied at the initial point by using
111112the ` initialization_eqs ` keyword argument, for example:
112113
113114``` @example init
114115prob = ODEProblem(pend, [x => 1], (0.0, 1.5), [g => 1], guesses = [λ => 0, y => 1],
115- initialization_eqs = [y ~ 1])
116+ initialization_eqs = [y ~ 1])
116117sol = solve(prob, Rodas5P())
117- plot(sol, idxs = (x,y))
118+ plot(sol, idxs = (x, y))
118119```
119120
120121Additionally, note that the initial conditions are allowed to be functions of other
121122variables and parameters:
122123
123124``` @example init
124- prob = ODEProblem(pend, [x => 1, D(y) => g], (0.0, 3.0), [g => 1], guesses = [λ => 0, y => 1])
125+ prob = ODEProblem(
126+ pend, [x => 1, D(y) => g], (0.0, 3.0), [g => 1], guesses = [λ => 0, y => 1])
125127sol = solve(prob, Rodas5P())
126- plot(sol, idxs = (x,y))
128+ plot(sol, idxs = (x, y))
127129```
128130
129131## Determinability: Underdetermined and Overdetermined Systems
130132
131133For this system we have 3 conditions to satisfy:
132134
133135``` @example init
134- conditions = getfield.(equations(pend)[3:end],:rhs)
136+ conditions = getfield.(equations(pend)[3:end], :rhs)
135137```
136138
137- when we initialize with
139+ when we initialize with
138140
139141``` @example init
140142prob = ODEProblem(pend, [x => 1, y => 0], (0.0, 1.5), [g => 1], guesses = [y => 0, λ => 1])
@@ -155,21 +157,22 @@ and thus the solution is not necessarily unique. It can still be solved:
155157
156158``` @example init
157159sol = solve(prob, Rodas5P())
158- plot(sol, idxs = (x,y))
160+ plot(sol, idxs = (x, y))
159161```
160162
161163and the found initial condition satisfies all constraints which were given. In the opposite
162164direction, we may have an overdetermined system:
163165
164166``` @example init
165- prob = ODEProblem(pend, [x => 1, y => 0.0, D(y) => 0], (0.0, 1.5), [g => 1], guesses = [λ => 1])
167+ prob = ODEProblem(
168+ pend, [x => 1, y => 0.0, D(y) => 0], (0.0, 1.5), [g => 1], guesses = [λ => 1])
166169```
167170
168171Can that be solved?
169172
170173``` @example init
171174sol = solve(prob, Rodas5P())
172- plot(sol, idxs = (x,y))
175+ plot(sol, idxs = (x, y))
173176```
174177
175178Indeed since we saw ` D(y) = 0 ` at the initial point above, it turns out that this solution
@@ -178,7 +181,8 @@ aren't that lucky. If the set of initial conditions cannot be satisfied, then yo
178181a ` SciMLBase.ReturnCode.InitialFailure ` :
179182
180183``` @example init
181- prob = ODEProblem(pend, [x => 1, y => 0.0, D(y) => 2.0, λ => 1], (0.0, 1.5), [g => 1], guesses = [λ => 1])
184+ prob = ODEProblem(
185+ pend, [x => 1, y => 0.0, D(y) => 2.0, λ => 1], (0.0, 1.5), [g => 1], guesses = [λ => 1])
182186sol = solve(prob, Rodas5P())
183187```
184188
@@ -216,18 +220,19 @@ with observables, those observables are too treated as initial equations. We can
216220resulting simplified system via the command:
217221
218222``` @example init
219- isys = structural_simplify(isys; fully_determined= false)
223+ isys = structural_simplify(isys; fully_determined = false)
220224```
221225
222226Note ` fully_determined=false ` allows for the simplification to occur when the number of equations
223227does not match the number of unknowns, which we can use to investigate our overdetermined system:
224228
225229``` @example init
226- isys = ModelingToolkit.generate_initializesystem(pend, u0map = [x => 1, y => 0.0, D(y) => 2.0, λ => 1], guesses = [λ => 1])
230+ isys = ModelingToolkit.generate_initializesystem(
231+ pend, u0map = [x => 1, y => 0.0, D(y) => 2.0, λ => 1], guesses = [λ => 1])
227232```
228233
229234``` @example init
230- isys = structural_simplify(isys; fully_determined= false)
235+ isys = structural_simplify(isys; fully_determined = false)
231236```
232237
233238``` @example init
@@ -252,8 +257,8 @@ constructor which acts just like an `ODEProblem` or `NonlinearProblem` construct
252257creates the special initialization system for a given ` sys ` . This is done as follows:
253258
254259``` @example init
255- iprob = ModelingToolkit.InitializationProblem(pend, 0.0,
256- [x => 1, y => 0.0, D(y) => 2.0, λ => 1], [g => 1], guesses = [λ => 1])
260+ iprob = ModelingToolkit.InitializationProblem(pend, 0.0,
261+ [x => 1, y => 0.0, D(y) => 2.0, λ => 1], [g => 1], guesses = [λ => 1])
257262```
258263
259264We can see that because the system is overdetermined we receive a NonlinearLeastSquaresProblem,
@@ -266,6 +271,7 @@ sol = solve(iprob)
266271```
267272
268273!!! note
274+
269275 For more information on solving NonlinearProblems and NonlinearLeastSquaresProblems,
270276 check out the [ NonlinearSolve.jl tutorials!] ( https://docs.sciml.ai/NonlinearSolve/stable/tutorials/getting_started/ ) .
271277
@@ -293,8 +299,8 @@ to see the problem is not equation 2 but other equations in the system. Meanwhil
293299some of the conditions:
294300
295301``` @example init
296- iprob = ModelingToolkit.InitializationProblem(pend, 0.0,
297- [x => 1, y => 0.0, D(y) => 0.0, λ => 0], [g => 1], guesses = [λ => 1])
302+ iprob = ModelingToolkit.InitializationProblem(pend, 0.0,
303+ [x => 1, y => 0.0, D(y) => 0.0, λ => 0], [g => 1], guesses = [λ => 1])
298304```
299305
300306gives a NonlinearLeastSquaresProblem which can be solved:
@@ -309,10 +315,9 @@ sol.resid
309315
310316In comparison, if we have a well-conditioned system:
311317
312-
313318``` @example init
314- iprob = ModelingToolkit.InitializationProblem(pend, 0.0,
315- [x => 1, y => 0.0], [g => 1], guesses = [λ => 1])
319+ iprob = ModelingToolkit.InitializationProblem(pend, 0.0,
320+ [x => 1, y => 0.0], [g => 1], guesses = [λ => 1])
316321```
317322
318323notice that we instead obtained a NonlinearSystem. In this case we have to use
@@ -348,7 +353,7 @@ by initializing the derivatives to zero:
348353
349354``` @example init
350355prob = ODEProblem(simpsys, [D(x) => 0.0, D(y) => 0.0], tspan, guesses = [x => 1, y => 1])
351- sol = solve(prob, Tsit5(), abstol= 1e-16)
356+ sol = solve(prob, Tsit5(), abstol = 1e-16)
352357```
353358
354359Notice that this is a "numerical zero", not an exact zero, and thus the solution will leave the
@@ -370,4 +375,4 @@ sol[α * x - β * x * y]
370375
371376``` @example init
372377plot(sol)
373- ```
378+ ```
0 commit comments