Skip to content

Commit ce51d34

Browse files
committed
cover TF initial condition warning in forced_response
1 parent 177290c commit ce51d34

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

control/tests/timeresp_test.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +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]
46+
siso_ss1.X0 = np.array([[.5], [1.]])
4747
siso_ss1.yinitial = np.array([11., 8.1494, 5.9361, 4.2258, 2.9118,
4848
1.9092, 1.1508, 0.5833, 0.1645, -0.1391])
4949
ss1 = siso_ss1.sys
@@ -586,17 +586,23 @@ def test_forced_response_step(self, tsystem):
586586
[np.zeros((10,), dtype=float),
587587
0] # special algorithm
588588
)
589-
@pytest.mark.parametrize("tsystem", ["siso_ss1"], indirect=True)
589+
@pytest.mark.parametrize("tsystem", ["siso_ss1", "siso_tf2"],
590+
indirect=True)
590591
def test_forced_response_initial(self, tsystem, u):
591-
"""Test forced response of SISO system as intitial response"""
592+
"""Test forced response of SISO system as intitial response."""
592593
sys = tsystem.sys
593594
t = tsystem.t
594-
x0 = np.array([[.5], [1.]])
595+
x0 = tsystem.X0
595596
yref = tsystem.yinitial
596597

597-
tout, yout = forced_response(sys, t, u, X0=x0)
598-
np.testing.assert_array_almost_equal(tout, t)
599-
np.testing.assert_array_almost_equal(yout, yref, decimal=4)
598+
if isinstance(sys, StateSpace):
599+
tout, yout = forced_response(sys, t, u, X0=x0)
600+
np.testing.assert_array_almost_equal(tout, t)
601+
np.testing.assert_array_almost_equal(yout, yref, decimal=4)
602+
else:
603+
with pytest.warns(UserWarning, match="Non-zero initial condition "
604+
"given for transfer function"):
605+
tout, yout = forced_response(sys, t, u, X0=x0)
600606

601607
@pytest.mark.parametrize("tsystem, useT",
602608
[("mimo_ss1", True),

0 commit comments

Comments
 (0)