Skip to content

Commit

Permalink
show that Symbol can also be used as an index
Browse files Browse the repository at this point in the history
  • Loading branch information
Datseris committed Feb 23, 2024
1 parent 3c94742 commit d9f8ad5
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions test/mtk_gui.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using DynamicalSystems, GLMakie, ModelingToolkit
# Import canonical time and time-derivative from MTK,
# however use the unitless versions as we don't need units here
using ModelingToolkit: t_nounits as t, D_nounits as D

# Define the variables and parameters in symbolic format
@variables t
D = Differential(t)
@parameters begin
a = 0.29
b = 0.14
c = 4.52
d = 1.0
end
@variables begin
x(t) = 10.0
Expand All @@ -20,11 +22,12 @@ eqs = [
D(x) ~ -y - z,
D(y) ~ x + a*y,
D(z) ~ b + nlt - z*c,
nlt ~ z*x, # observed variable
nlt ~ d*z*x, # observed variable
]

# Create the model via ModelingToolkit
@named roessler = ODESystem(eqs)
@named roessler = ODESystem(eqs, t)
# Do not split parameters so that integer indexing can be used as well
model = structural_simplify(roessler; split = false)
# Cast it into an `ODEProblem` and then into a `DynamicalSystem`
prob = ODEProblem(model)
Expand All @@ -38,16 +41,19 @@ parameter_sliders = Dict(
1 => 0:0.01:1,
# the global scope symbol
b => 0:0.01:1,
# or the symbol obtained from the MTK model
# the symbol obtained from the MTK model
model.c => 0:0.01:10,
# or a `Symbol` with same name as the parameter
:d => 0.8:0.01:1.2,
)

# Define what variables will be visualized as timeseries
norm(u) = sqrt(u[1]*u[1] + u[2]*u[2])
observables = [
1, # can use integer indexing,
z, # MTK state variable
z, # MTK state variable (unknown)
model.nlt, # MTK observed variable
:y, # `Symbol` instance with same name
norm, # or arbitrary function of the state
]

Expand Down

0 comments on commit d9f8ad5

Please sign in to comment.