JuliaControl / ControlSystems.jl

A Control Systems Toolbox for Julia
https://juliacontrol.github.io/ControlSystems.jl/stable/
Other
510 stars 85 forks source link

Step response (at a t0 instant) of a first order system with delay doesn't work correctly with lsim (but works fine with step but with t0=0) #920

Closed scls19fr closed 7 months ago

scls19fr commented 7 months ago

Hello,

using ControlSystems
using Plots
τ = 2.0  # s (time constant)
td = 0.5  # s (delay)
K = 1
T1 = K / (1 + τ * s) * delay(td)
plot(rep, label=["output" "input"], plotu=true, ploty=true)
ylims!(-0.15, 1.15)

plots

image

but

t = 0:0.01:10
t0 = 1.0
u = 2.0 * (t .>= t0)'
res = lsim(T1, u, t)
plot(res, label=["output" "input"], plotu=true, ploty=true)

raises

No methods were found for the model function passed to the equation solver.

The function `f` needs to have dispatches, for example, for an ODEProblem

`f` must define either `f(u,p,t)` or `f(du,u,p,t)`. For more information

on how the model function `f` should be defined, consult the docstring for

the appropriate `AbstractSciMLFunction`.

...

PS : but it works fine with pade https://github.com/JuliaControl/ControlSystems.jl/blob/0d825400f1fd0126a4ccaa63408ba2b38351d47a/lib/ControlSystemsBase/src/delay_systems.jl#L128-L134

mzaffalon commented 7 months ago

u must a function of the state x and time t: see https://juliacontrol.github.io/ControlSystems.jl/stable/lib/timefreqresponse/#ControlSystemsBase.lsim-Tuple{AbstractStateSpace,%20AbstractVecOrMat,%20AbstractVector}

scls19fr commented 7 months ago
u = (x, t) -> (t < t0 ? 0 : 1)

this is function of the state x and time t but it raises now

u must be a vector of size (1,)

Sorry for my questions!

scls19fr commented 7 months ago
u = (x, t) -> (t < t0 ? [0] : [1])

works fine but is quite tricky (especially when dealing with SISO systems

t = 0:0.01:10
t0 = 1.0
u = (x, t) -> (t < t0 ? [0] : [1])
res = lsim(T1, u, t)
plot(res, label=["output" "input"], plotu=true, sp=[2 1])

image

baggepinnen commented 7 months ago

Try

u = (x, t) -> [t < t0]
scls19fr commented 7 months ago

Thanks

u = (x, t) -> 2 * [t > t0]

works fine