ModelingToolkit.jl icon indicating copy to clipboard operation
ModelingToolkit.jl copied to clipboard

ODESystem doesn't check parameters and variables are disjoint

Open qwertyjl opened this issue 3 years ago • 2 comments

If i try to get a numerical solution to this ODE system i don't get the correct result.

# This code is inspired by the one found as an example in README.md
p₀, q₀ = 0.0, 3.0

@variables t
@parameters P(t) Q(t)
∂t = Differential(t)

eqs = [∂t(Q) ~ 0.2P
       ∂t(P) ~ -80.0sin(Q)]
@named sys = ODESystem(eqs)

u₀ = [P=>p₀, Q=>q₀]

t_span = (0.0, 20.0)
prob = ODEProblem(sys, u₀, t_span)
sol = solve(prob, Tsit5())

By declaring Q and P as variables I get the right result. Maybe there is a problem. https://discourse.julialang.org/t/solving-system-of-ode-with-modeling-toolkit/85524/2

qwertyjl avatar Aug 09 '22 13:08 qwertyjl

Just to clarify, writing

@parameters P(t) Q(t)

is wrong. It should be @variables. We could have better error messages though.

YingboMa avatar Aug 09 '22 18:08 YingboMa

Sorry, my mistake. There are no problems in Modeling Toolkit. Thanks for the reply.

qwertyjl avatar Aug 09 '22 21:08 qwertyjl