Skip to content

Observed variable calculated incorrectly using new discrete parameters #3199

@bradcarman

Description

@bradcarman

MWE with discrete parameter heading(t)...

using ModelingToolkit
using ModelingToolkit: t_nounits as t, D_nounits as D
using OrdinaryDiffEq
using Plots

inch = 25.4e-3
sec = 1
rate = 2*inch/sec
L = 4*inch

pars = @parameters begin
    heading(t) = 1
end

vars = @variables begin
    x(t) = 0
    dx(t) = rate
end

eqs = [
    dx ~ heading*rate
    D(x) ~ dx
]

events = [
    [x~0] => [heading ~ +1]
    [x~L] => [heading ~ -1]
]

@mtkbuild sys = ODESystem(eqs, t, vars, pars; continuous_events=events)
prob = ODEProblem(sys, [], (0, 8))
sol = solve(prob)
 
plot(sol; idxs=x)
plot(sol; idxs=dx)
plot(sol; idxs=heading)

This gives the correct result for x and heading

image
image

However, the observed variable dx plots a constant value...

image

As can be seen, the observed function for dx is

julia> observed(sys)
1-element Vector{Equation}:
 dx(t) ~ 0.0508heading(t)

Which means the calculation of dx is not handling the change in heading correctly.

Metadata

Metadata

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