Skip to content

Commit 177290c

Browse files
committed
reactivate the the fast forced_response(U=0) algorithm and test it
1 parent a72441b commit 177290c

2 files changed

Lines changed: 15 additions & 8 deletions

File tree

control/tests/timeresp_test.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def tsystem(self, request):
4343
siso_ss1.ystep = np.array([9., 17.6457, 24.7072, 30.4855, 35.2234,
4444
39.1165, 42.3227, 44.9694, 47.1599,
4545
48.9776])
46+
# X0 = [0.5, 1]
4647
siso_ss1.yinitial = np.array([11., 8.1494, 5.9361, 4.2258, 2.9118,
4748
1.9092, 1.1508, 0.5833, 0.1645, -0.1391])
4849
ss1 = siso_ss1.sys
@@ -127,6 +128,7 @@ def tsystem(self, request):
127128

128129
siso_dss1 = copy(siso_dtf1)
129130
siso_dss1.sys = tf2ss(siso_dtf1.sys)
131+
siso_dss1.yinitial = np.array([-1., -0.5, 0.75, -0.625, 0.4375])
130132

131133
siso_dss2 = copy(siso_dtf2)
132134
siso_dss2.sys = tf2ss(siso_dtf2.sys)
@@ -641,19 +643,23 @@ def test_forced_response_legacy(self):
641643
[pytest.param("siso_ss1",
642644
{'X0': [0.5, 1], 'T': np.linspace(0, 1, 10)},
643645
'yinitial',
644-
id="ctime no T"),
646+
id="ctime no U"),
647+
pytest.param("siso_dss1",
648+
{'T': np.arange(0, 5, 1,),
649+
'X0': [0.5, 1]}, 'yinitial',
650+
id="dt=True, no U"),
645651
pytest.param("siso_dtf1",
646652
{'U': np.ones(5,)}, 'ystep',
647-
id="dt=True, no U"),
653+
id="dt=True, no T"),
648654
pytest.param("siso_dtf2",
649655
{'U': np.ones(25,)}, 'ystep',
650-
id="dt=0.2, no U"),
656+
id="dt=0.2, no T"),
651657
pytest.param("siso_ss2_dtnone",
652658
{'U': np.ones(10,)}, 'ystep',
653-
id="dt=None, no U"),
659+
id="dt=None, no T"),
654660
pytest.param("siso_dtf3",
655661
{'U': np.ones(10,)}, 'ystep',
656-
id="dt with rounding error"),
662+
id="dt with rounding error, no T"),
657663
],
658664
indirect=["tsystem"])
659665
def test_forced_response_T_U(self, tsystem, fr_kwargs, refattr):
@@ -668,13 +674,13 @@ def test_forced_response_invalid_c(self, tsystem):
668674
with pytest.raises(TypeError,
669675
match="StateSpace.*or.*TransferFunction"):
670676
forced_response("not a system")
671-
672-
# ctime
673677
with pytest.raises(ValueError, match="T.*is mandatory for continuous"):
674678
forced_response(tsystem.sys)
675679
with pytest.raises(ValueError, match="time values must be equally "
676680
"spaced"):
677681
forced_response(tsystem.sys, [0, 0.1, 0.12, 0.4])
682+
with pytest.raises(ValueError, match="must start with 0"):
683+
forced_response(tsystem.sys, [1, 1.1, 1.2, 1.3])
678684

679685
@pytest.mark.parametrize("tsystem", ["siso_dss2"], indirect=True)
680686
def test_forced_response_invalid_d(self, tsystem):

control/timeresp.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,8 @@ def forced_response(sys, T=None, U=0., X0=0., transpose=False,
379379
dot = np.dot # Faster and shorter code
380380

381381
# Faster algorithm if U is zero
382-
if U is None or (isinstance(U, (int, float)) and U == 0):
382+
# (if not None, it was converted to array above)
383+
if U is None or np.all(U == 0):
383384
# Solve using matrix exponential
384385
expAdt = sp.linalg.expm(A * dt)
385386
for i in range(1, n_steps):

0 commit comments

Comments
 (0)