Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug with delay in hold operator #2707

Open
baggepinnen opened this issue May 9, 2024 · 0 comments
Open

Bug with delay in hold operator #2707

baggepinnen opened this issue May 9, 2024 · 0 comments
Labels
bug Something isn't working discrete-time

Comments

@baggepinnen
Copy link
Contributor

The following construct is equivalent to delaying a signal by 2 samples. but the result is that the output is constantly zero. The expected output is a step from 0 to 1 at t=4.

delay(k) ~ input(k - 1)
Hold(delay(k-1))
using ModelingToolkit: t_nounits as t, D_nounits as D
k = ShiftIndex(Clock(t, 1))
@mtkmodel DelayModel begin
    @variables begin
        input(t) = 0
        delay(t) = 0
        x(t) = 0
    end
    @equations begin
        input ~ (t >= 2)
        delay(k) ~ input(k - 1)
        D(x) ~ (-x + Hold(delay(k-1))) / 1e-3
    end
end

@mtkbuild m = DelayModel()
prob = ODEProblem(
    m, [m.delay(k - 3) => 0, m.delay(k - 2) => 0, m.delay(k - 1) => 0], (0.0, 10.0))
sol = solve(prob, Tsit5(), kwargshandle = KeywordArgSilent, dtmax = 0.5)
plot(sol, idxs=m.x)
@baggepinnen baggepinnen added bug Something isn't working discrete-time labels May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working discrete-time
Projects
None yet
Development

No branches or pull requests

1 participant