Skip to content

Commit cc90d8d

Browse files
committed
include tfinal in auto generated timevector
1 parent 238482e commit cc90d8d

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

control/tests/sisotool_test.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ def test_sisotool(self, sys):
6868

6969
# Check the step response before moving the point
7070
step_response_original = np.array(
71-
[0. , 0.021 , 0.124 , 0.3146, 0.5653, 0.8385, 1.0969, 1.3095,
72-
1.4549, 1.5231])
71+
[0. , 0.0216, 0.1271, 0.3215, 0.5762, 0.8522, 1.1114, 1.3221,
72+
1.4633, 1.5254])
7373
assert_array_almost_equal(
7474
ax_step.lines[0].get_data()[1][:10], step_response_original, 4)
7575

@@ -113,8 +113,8 @@ def test_sisotool(self, sys):
113113

114114
# Check if the step response has changed
115115
step_response_moved = np.array(
116-
[0. , 0.023 , 0.1554, 0.4401, 0.8646, 1.3722, 1.875 , 2.2709,
117-
2.4633, 2.3827])
116+
[0. , 0.0237, 0.1596, 0.4511, 0.884 , 1.3985, 1.9031, 2.2922,
117+
2.4676, 2.3606])
118118
assert_array_almost_equal(
119119
ax_step.lines[0].get_data()[1][:10], step_response_moved, 4)
120120

@@ -157,7 +157,3 @@ def test_sisotool_mimo(self, sys222, sys221):
157157
# but 2 input, 1 output should
158158
with pytest.raises(ControlMIMONotImplemented):
159159
sisotool(sys221)
160-
161-
162-
163-

control/timeresp.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,16 +1303,18 @@ def _default_time_vector(sys, N=None, tfinal=None, is_step=True):
13031303
# only need to use default_tfinal if not given; N is ignored.
13041304
if tfinal is None:
13051305
# for discrete time, change from ideal_tfinal if N too large/small
1306-
N = int(np.clip(ideal_tfinal/sys.dt, N_min_dt, N_max))# [N_min, N_max]
1307-
tfinal = sys.dt * N
1306+
# [N_min, N_max]
1307+
N = int(np.clip(np.ceil(ideal_tfinal/sys.dt)+1, N_min_dt, N_max))
1308+
tfinal = sys.dt * (N-1)
13081309
else:
1309-
N = int(tfinal/sys.dt)
1310-
tfinal = N * sys.dt # make tfinal an integer multiple of sys.dt
1310+
N = int(np.ceil(tfinal/sys.dt)) + 1
1311+
tfinal = sys.dt * (N-1) # make tfinal an integer multiple of sys.dt
13111312
else:
13121313
if tfinal is None:
13131314
# for continuous time, simulate to ideal_tfinal but limit N
13141315
tfinal = ideal_tfinal
13151316
if N is None:
1316-
N = int(np.clip(tfinal/ideal_dt, N_min_ct, N_max)) # N<-[N_min, N_max]
1317+
# [N_min, N_max]
1318+
N = int(np.clip(np.ceil(tfinal/ideal_dt)+1, N_min_ct, N_max))
13171319

1318-
return np.linspace(0, tfinal, N, endpoint=False)
1320+
return np.linspace(0, tfinal, N, endpoint=True)

0 commit comments

Comments
 (0)