Created
February 22, 2021 13:35
-
-
Save pbouffard/b2cf4c4b0bc23d4693567a5714e2290c to your computer and use it in GitHub Desktop.
Error trying to chain 2 simple ODEs in ModelingToolkit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using ModelingToolkit | |
@parameters t a | |
@variables x(t) f(t) | |
D = Differential(t) | |
eqs = [ | |
D(x) ~ -a*x + f | |
] | |
decay = name -> ODESystem(eqs, name=name) | |
decay1 = decay(:decay1) | |
decay2 = decay(:decay2) | |
connected = ODESystem([ | |
decay2.f ~ decay1.x | |
], t, systems=[decay1, decay2]) | |
reduced_system = alias_elimination(connected; conservative=false) | |
@show reduced_system | |
x0 = [ | |
decay1.x => 1.0 | |
decay1.f => 0.0 | |
decay2.x => 1.0 | |
] | |
p = [ | |
decay1.a => 0.1 | |
decay2.a => 0.2 | |
] | |
# produces ERROR: BoundsError: attempt to access 2×2 Matrix{Float64} at index [2, 3] | |
prob = ODEProblem(reduced_system, x0, (0.0, 20.0), p) | |
sol = solve(prob) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Full output: