Skip to content

Commit ce31629

Browse files
committed
Upper-bound length of default time vector
closes #880
1 parent 16aa4bc commit ce31629

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

lib/ControlSystemsBase/src/timeresp.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ function _default_time_vector(sys::LTISystem, tfinal::Real=-1)
415415
ω0_min = minimum(w for w in ws if w > 1e-6; init=dt)
416416
dt_slow = round(1/(2ω0_min), sigdigits=2)
417417
tfinal = max(200dt, dt_slow)
418+
tfinal = min(tfinal, 100_000*dt)
418419
else
419420
tfinal = 200dt
420421
end

test/test_timeresp.jl

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,23 @@ s = tf('s')
138138
sys = 0.0002/s^2;
139139
t = 0:0.01:10
140140
u1(x,t) = [25(5.0 <= t < 5.1)]
141-
@test lsim(sys, u1, t; ).y[end] lsim(sys, u1, t; method=:zoh).y[end] rtol=0.1
141+
@test lsim(sys, u1, t; ).y[end] lsim(sys, u1, t; method=:zoh).y[end] rtol=0.1
142+
143+
144+
## Slow and fast time constants make reasonable length time vector (https://github.com/JuliaControl/ControlSystems.jl/issues/880)
145+
A =
146+
[ -6538.4 -40.38 0.0 0.0;
147+
409.6 0.0 0.0 0.0;
148+
0.0 0.9164 -28.28 -20.0;
149+
0.0 0.0 20.0 0.0]
150+
B =
151+
[ 3846.15 0.0;
152+
0.0 -288.0;
153+
0.0 0.0;
154+
0.0 0.0]
155+
C =[ 0.0 0.0 0.0 1.0]
156+
D =[ 0.0 0.0]
157+
158+
sys = ss(A,B,C,D)
159+
@test length(ControlSystemsBase._default_time_vector(sys)) <= 1e5+1
160+
@test step(sys) isa ControlSystemsBase.SimResult

0 commit comments

Comments
 (0)