28
28
@testset " Change independent variable (trivial)" begin
29
29
@variables x (t) y (t)
30
30
eqs1 = [D (D (x)) ~ D (x) + x, D (y) ~ 1 ]
31
- M1 = ODESystem (eqs1, t; name = :M ) |> complete
32
- M2 = change_independent_variable (M1, M1 . y)
31
+ M1 = ODESystem (eqs1, t; name = :M )
32
+ M2 = change_independent_variable (M1, y)
33
33
eqs2 = substitute (equations (M2), M2. y => M1. t) # system should be equivalent when parametrized with y (since D(y) ~ 1), so substitute back ...
34
34
@test eqs1[1 ] == only (eqs2) # ... and check that the equations are unmodified
35
35
end
43
43
D (s) ~ 1 / (2 * s)
44
44
]
45
45
initialization_eqs = [x ~ 1.0 , y ~ 1.0 , D (y) ~ 0.0 ]
46
- M1 = ODESystem (eqs, t; initialization_eqs, name = :M ) |> complete
47
- M2 = change_independent_variable (M1, M1 . s; dummies = true )
46
+ M1 = ODESystem (eqs, t; initialization_eqs, name = :M )
47
+ M2 = change_independent_variable (M1, s; dummies = true )
48
48
49
49
M1 = structural_simplify (M1; allow_symbolic = true )
50
50
M2 = structural_simplify (M2; allow_symbolic = true )
75
75
]
76
76
M1 = ODESystem (eqs, t, [Ω, a, ȧ, ϕ], []; name = :M )
77
77
M1 = compose (M1, r, m, Λ)
78
- M1 = complete (M1; flatten = false )
79
78
80
79
# Apply in two steps, where derivatives are defined at each step: first t -> a, then a -> b
81
80
M2 = change_independent_variable (M1, M1. a; dummies = true )
82
- a, ȧ, Ω, Ωr, Ωm, ΩΛ, ϕ, aˍt, aˍtt = M2. a, M2. ȧ, M2. Ω, M2. r. Ω, M2. m. Ω, M2. Λ. Ω, M2. ϕ, M2. aˍt, M2. aˍtt
81
+ M2c = complete (M2) # just for the following equation comparison (without namespacing)
82
+ a, ȧ, Ω, Ωr, Ωm, ΩΛ, ϕ, aˍt, aˍtt = M2c. a, M2c. ȧ, M2c. Ω, M2c. r. Ω, M2c. m. Ω, M2c. Λ. Ω, M2c. ϕ, M2c. aˍt, M2c. aˍtt
83
83
Da = Differential (a)
84
84
@test Set (equations (M2)) == Set ([
85
85
aˍt ~ ȧ # 1st order dummy equation
@@ -103,16 +103,16 @@ end
103
103
104
104
@testset " Change independent variable (simple)" begin
105
105
@variables x (t)
106
- Mt = ODESystem ([D (x) ~ 2 * x], t; name = :M ) |> complete
107
- Mx = change_independent_variable (Mt, Mt . x; dummies = true )
106
+ Mt = ODESystem ([D (x) ~ 2 * x], t; name = :M )
107
+ Mx = change_independent_variable (Mt, x; dummies = true )
108
108
@test (@variables x xˍt (x) xˍtt (x); Set (equations (Mx)) == Set ([xˍt ~ 2 * x, xˍtt ~ 2 * xˍt]))
109
109
end
110
110
111
111
@testset " Change independent variable (free fall)" begin
112
112
@variables x (t) y (t)
113
113
@parameters g v # gravitational acceleration and constant horizontal velocity
114
- Mt = ODESystem ([D (D (y)) ~ - g, D (x) ~ v], t; name = :M ) |> complete # gives (x, y) as function of t, ...
115
- Mx = change_independent_variable (Mt, Mt . x; dummies = false ) # ... but we want y as a function of x
114
+ Mt = ODESystem ([D (D (y)) ~ - g, D (x) ~ v], t; name = :M ) # gives (x, y) as function of t, ...
115
+ Mx = change_independent_variable (Mt, x; dummies = false ) # ... but we want y as a function of x
116
116
Mx = structural_simplify (Mx; allow_symbolic = true )
117
117
Dx = Differential (Mx. x)
118
118
prob = ODEProblem (Mx, [Mx. y => 0.0 , Dx (Mx. y) => 1.0 ], (0.0 , 20.0 ), [g => 9.81 , v => 10.0 ]) # 1 = dy/dx = (dy/dt)/(dx/dt) means equal initial horizontal and vertical velocities
127
127
M1 = ODESystem ([ # crazy non-autonomous non-linear 2nd order ODE
128
128
D (D (y)) ~ D (x)^ 2 + D (y^ 3 ) |> expand_derivatives # expand D(y^3) # TODO : make this test 3rd order
129
129
D (x) ~ x^ 4 + y^ 5 + t^ 6
130
- ], t; name = :M ) |> complete
131
- M2 = change_independent_variable (M1, M1 . x; dummies = true )
130
+ ], t; name = :M )
131
+ M2 = change_independent_variable (M1, x; dummies = true )
132
132
133
133
# Compare to pen-and-paper result
134
134
@independent_variables x
@@ -144,18 +144,16 @@ end
144
144
@testset " Change independent variable (errors)" begin
145
145
@variables x (t) y z (y) w (t) v (t)
146
146
M = ODESystem ([D (x) ~ 0 , v ~ x], t; name = :M )
147
- @test_throws " incomplete" change_independent_variable (M, M. x)
148
- M = complete (M)
149
- @test_throws " singular" change_independent_variable (M, M. x)
147
+ @test_throws " singular" change_independent_variable (M, x)
150
148
@test_throws " structurally simplified" change_independent_variable (structural_simplify (M), y)
151
149
@test_throws " Got 0 equations:" change_independent_variable (M, w)
152
150
@test_throws " Got 0 equations:" change_independent_variable (M, v)
153
- M = ODESystem ([D (x) ~ 1 , v ~ 1 ], t; name = :M ) |> complete
154
- @test_throws " Got 2 equations:" change_independent_variable (M, M . x, [D (x) ~ 2 ])
151
+ M = ODESystem ([D (x) ~ 1 , v ~ 1 ], t; name = :M )
152
+ @test_throws " Got 2 equations:" change_independent_variable (M, x, [D (x) ~ 2 ])
155
153
@test_throws " not a function of the independent variable" change_independent_variable (M, y)
156
154
@test_throws " not a function of the independent variable" change_independent_variable (M, z)
157
155
M = ODESystem ([D (x) ~ 0 , v ~ x], t; name = :M )
158
156
@variables x (.. ) # require explicit argument
159
- M = ODESystem ([D (x (t)) ~ x (t- 1 )], t; name = :M ) |> complete
160
- @test_throws " DDE" change_independent_variable (M, M . x )
157
+ M = ODESystem ([D (x (t)) ~ x (t- 1 )], t; name = :M )
158
+ @test_throws " DDE" change_independent_variable (M, x (t) )
161
159
end
0 commit comments