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 " 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."""