diff --git a/lib/ControlSystemsBase/src/timeresp.jl b/lib/ControlSystemsBase/src/timeresp.jl index 9c36480f4..6088f0c61 100644 --- a/lib/ControlSystemsBase/src/timeresp.jl +++ b/lib/ControlSystemsBase/src/timeresp.jl @@ -415,6 +415,7 @@ function _default_time_vector(sys::LTISystem, tfinal::Real=-1) ω0_min = minimum(w for w in ws if w > 1e-6; init=dt) dt_slow = round(1/(2ω0_min), sigdigits=2) tfinal = max(200dt, dt_slow) + tfinal = min(tfinal, 100_000*dt) else tfinal = 200dt end diff --git a/test/test_timeresp.jl b/test/test_timeresp.jl index e6b68f1f3..77314f4bc 100644 --- a/test/test_timeresp.jl +++ b/test/test_timeresp.jl @@ -138,4 +138,23 @@ s = tf('s') sys = 0.0002/s^2; t = 0:0.01:10 u1(x,t) = [25(5.0 <= t < 5.1)] -@test lsim(sys, u1, t; ).y[end] ≈ lsim(sys, u1, t; method=:zoh).y[end] rtol=0.1 \ No newline at end of file +@test lsim(sys, u1, t; ).y[end] ≈ lsim(sys, u1, t; method=:zoh).y[end] rtol=0.1 + + +## Slow and fast time constants make reasonable length time vector (https://github.com/JuliaControl/ControlSystems.jl/issues/880) +A = +[ -6538.4 -40.38 0.0 0.0; + 409.6 0.0 0.0 0.0; + 0.0 0.9164 -28.28 -20.0; + 0.0 0.0 20.0 0.0] +B = +[ 3846.15 0.0; + 0.0 -288.0; + 0.0 0.0; + 0.0 0.0] +C =[ 0.0 0.0 0.0 1.0] +D =[ 0.0 0.0] + +sys = ss(A,B,C,D) +@test length(ControlSystemsBase._default_time_vector(sys)) <= 1e5+1 +@test step(sys) isa ControlSystemsBase.SimResult \ No newline at end of file