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

System with only discrete-time variables being treated as continuous time #2700

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

Comments

@baggepinnen
Copy link
Contributor

The following model contains only discrete-time variables. It simplifies and solves, but the solution is completely incorrect, possibly because it is being incorrectly treated as a continuous-time system

using ModelingToolkit
using ModelingToolkitStandardLibrary.Blocks
using ModelingToolkit: t_nounits as t
k = ShiftIndex()
@mtkmodel Del begin
    @extend u, y = siso = SISO()
    @structural_parameters begin
        n = 1
    end
    @equations begin
        y ~ u(k-n)
    end
end

@mtkmodel DelayModel begin
    @components begin
        delay = Del(n = 3)
        input = Constant(k = 1)
    end
    @equations begin
        connect(input.output, delay.input)
    end
end

@mtkbuild m = DelayModel()
prob = ODEProblem(m, [m.delay.u(k-3)=>0, m.delay.u(k-2)=>0, m.delay.u(k-1)=>0], (0.0, 10.0))

sol = solve(prob, Tsit5())

The solution should have only 1 and 0 elements

julia> sol.u
7-element Vector{Vector{Float64}}:
 [0.0, 0.0, 0.0]
 [9.999999999999996e-5, 4.9999999999999695e-9, 1.6666666666666627e-13]
 [0.0010999999999999996, 6.049999999999966e-7, 2.2183333333333146e-10]
 [0.011099999999999994, 6.160499999999969e-5, 2.2793849999999778e-7]
 [0.11109999999999993, 0.00617160499999997, 0.0002285551051666657]
 [1.1110999999999993, 0.6172716049999964, 0.22861682677183132]
 [9.999999999999996, 49.99999999999975, 166.6666666666658]

The solution here is $t, \frac{t^2}{2}, \frac{t^3}{6}$, which happens to be correct for a continuous-time triple-integrator system.

Also:

using Plots
plot(sol) # errors
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

2 participants