Skip to content

Commit

Permalink
Merge pull request #887 from JuliaControl/defaulttime
Browse files Browse the repository at this point in the history
Upper-bound length of default time vector
  • Loading branch information
baggepinnen committed Oct 12, 2023
2 parents 16aa4bc + ce31629 commit 71091fc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/ControlSystemsBase/src/timeresp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 20 additions & 1 deletion test/test_timeresp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
@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

0 comments on commit 71091fc

Please sign in to comment.