From 7b04c01fd5499dd1e2c4c33e1281bfbafa2ee8b3 Mon Sep 17 00:00:00 2001 From: Richard Murray Date: Sat, 7 Jul 2018 13:26:08 -0700 Subject: [PATCH 1/2] add unit test for state space system with no transmission zero --- control/tests/statesp_test.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/control/tests/statesp_test.py b/control/tests/statesp_test.py index fe1293fb5..35f511ab1 100644 --- a/control/tests/statesp_test.py +++ b/control/tests/statesp_test.py @@ -42,6 +42,11 @@ def testPole(self): np.testing.assert_array_almost_equal(p, true_p) + def testEmptyZero(self): + """Test to make sure zero() works with no zeros in system""" + sys = _convertToStateSpace(TransferFunction([1], [1,2,1])) + np.testing.assert_array_equal(sys.zero(), np.array([])) + @unittest.skipIf(not slycot_check(), "slycot not installed") def testMIMOZero_nonsquare(self): """Evaluate the zeros of a MIMO system.""" From 87ec281f29593f10655d40b6911e013259180882 Mon Sep 17 00:00:00 2001 From: Richard Murray Date: Sat, 7 Jul 2018 13:29:34 -0700 Subject: [PATCH 2/2] fix empty transmission zero bug for state space systems --- control/statesp.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/control/statesp.py b/control/statesp.py index adb86adbc..4a617abd2 100644 --- a/control/statesp.py +++ b/control/statesp.py @@ -525,7 +525,11 @@ def zero(self): out = ab08nd(self.A.shape[0], self.B.shape[1], self.C.shape[0], self.A, self.B, self.C, self.D) nu = out[0] - return sp.linalg.eigvals(out[8][0:nu,0:nu], out[9][0:nu,0:nu]) + if nu == 0: + return np.array([]) + else: + return sp.linalg.eigvals(out[8][0:nu,0:nu], out[9][0:nu,0:nu]) + except ImportError: # Slycot unavailable. Fall back to scipy. if self.C.shape[0] != self.D.shape[1]: raise NotImplementedError("StateSpace.zero only supports "