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