Skip to content

Commit 3155a5d

Browse files
committed
Clean up example
1 parent f2a1a5a commit 3155a5d

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

docs/src/tutorials/change_independent_variable.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ M1 = ODESystem([
2727
D(x) ~ D(y) # equal initial horizontal and vertical velocity (45°)
2828
], name = :M)
2929
M1s = structural_simplify(M1)
30+
@assert length(equations(M1s)) == 3 # hide
31+
M1s # hide
3032
```
3133
This is the standard parametrization that arises naturally from kinematics and Newton's laws.
3234
It expresses the position $(x(t), y(t))$ as a function of time $t$.
@@ -46,6 +48,7 @@ M2s = structural_simplify(M2; allow_symbolic = true)
4648
@assert allequal([M2.x, M2s.x]) # hide
4749
@assert allequal([y, M1s.y]) # hide
4850
@assert allunique([M1.x, M1.y, M2.y, M2s.y]) # hide
51+
@assert length(equations(M2s)) == 2 # hide
4952
M2s # display this # hide
5053
```
5154
The derivatives are now with respect to the new independent variable $x$, which can be accessed with `M2.x`.
@@ -101,7 +104,7 @@ sol = solve(prob, Tsit5(); reltol = 1e-5)
101104
@assert Symbol(sol.retcode) == :Unstable # surrounding text assumes this was unstable # hide
102105
plot(sol, idxs = [M1.a, M1.r.Ω/M1.Ω, M1.m.Ω/M1.Ω, M1.Λ.Ω/M1.Ω])
103106
```
104-
The solver becomes unstable due to stiffness.
107+
But the solver becomes unstable due to stiffness.
105108
Also notice the interesting dynamics taking place towards the end of the integration (in the early universe), which gets compressed into a very small time interval.
106109
These ODEs would benefit from being defined with respect to a logarithmic "time" that better captures the evolution of the universe through *orders of magnitude* of time.
107110

@@ -111,6 +114,8 @@ Notice that $\mathrm{d}a/\mathrm{d}t > 0$ provided that $\Omega > 0$, and $\math
111114
First, we transform from $t$ to $a$:
112115
```@example changeivar
113116
M2 = change_independent_variable(M1, M1.a)
117+
@assert !ModelingToolkit.isautonomous(M2) # hide
118+
M2 # hide
114119
```
115120
Unlike the original, notice that this system is *non-autonomous* because the independent variable $a$ appears explicitly in the equations!
116121
This means that to change the independent variable from $a$ to $b$, we must provide not only the rate of change relation $db(a)/da = \exp(-b)$, but *also* the equation $a(b) = \exp(b)$ so $a$ can be eliminated in favor of $b$:

0 commit comments

Comments
 (0)