Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upper-bound length of default time vector #887

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading