Skip to content

Can create and simulate ODE without providing initial conditions for all variables #4104

@TorkelE

Description

@TorkelE

Pretty serious, leads to a silent and potentially nasty error.

# Fetch packages
using ModelingToolkitBase
using OrdinaryDiffEqDefault
using ModelingToolkitBase: t_nounits as t, D_nounits as D

# Create model.
@variables X1(t) X2(t)
@parameters k1 k2
eqs = [
    D(X1) ~ -k1*X1 + k2*X2
    D(X2) ~ k1*X1 - k2*X2
]
@mtkbuild sys = System(eqs, t)

sim_conds = [X1 => 3.4, k1 => 1.2, k2 => 0.13]
oprob = ODEProblem(sys, sim_conds, (0.0, 1.0))
sol = solve(oprob)

oprob[X1] # 3.4
oprob[X2] # 1.0
sol[X1][1] # 3.4
sol[X2][1] # 1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions