def testPlace_varga_continuous(self): """ Check that we can place eigenvalues for dtime=False """ A = np.array([[1., -2.], [3., -4.]]) B = np.array([[5.], [7.]]) P = np.array([-2., -2.]) K = place_varga(A, B, P) P_placed = np.linalg.eigvals(A - B.dot(K)) # No guarantee of the ordering, so sort them P.sort() P_placed.sort() np.testing.assert_array_almost_equal(P, P_placed) # Test that the dimension checks work. np.testing.assert_raises(ControlDimension, place, A[1:, :], B, P) np.testing.assert_raises(ControlDimension, place, A, B[1:, :], P) # Regression test against bug #177 # https://github.com/python-control/python-control/issues/177 A = np.array([[0, 1], [100, 0]]) B = np.array([[0], [1]]) P = np.array([-20 + 10*1j, -20 - 10*1j]) K = place_varga(A, B, P) P_placed = np.linalg.eigvals(A - B.dot(K)) # No guarantee of the ordering, so sort them P.sort() P_placed.sort() np.testing.assert_array_almost_equal(P, P_placed)
def testPlace_varga_discrete(self, matarrayin): """ Check that we can place poles using dtime=True (discrete time) """ A = matarrayin([[1., 0], [0, 0.5]]) B = matarrayin([[5.], [7.]]) P = matarrayin([0.5, 0.5]) K = place_varga(A, B, P, dtime=True) P_placed = np.linalg.eigvals(A - B @ K) # No guarantee of the ordering, so sort them self.checkPlaced(P, P_placed)
def testPlace_varga_discrete(self): """ Check that we can place poles using dtime=True (discrete time) """ A = np.array([[1., 0], [0, 0.5]]) B = np.array([[5.], [7.]]) P = np.array([0.5, 0.5]) K = place_varga(A, B, P, dtime=True) P_placed = np.linalg.eigvals(A - B.dot(K)) # No guarantee of the ordering, so sort them P.sort() P_placed.sort() np.testing.assert_array_almost_equal(P, P_placed)
def testPlace_varga_discrete_partial_eigs(self, matarrayin): """" Check that we can only assign a single eigenvalue in the discrete time case. """ # A matrix has eigenvalues at 1.0 and 0.5. Set alpha = 0.51, and # check that the eigenvalue at 0.5 is not moved. A = matarrayin([[1., 0], [0, 0.5]]) B = matarrayin([[5.], [7.]]) P = matarrayin([0.2, 0.6]) P_expected = np.array([0.5, 0.6]) alpha = 0.51 K = place_varga(A, B, P, dtime=True, alpha=alpha) P_placed = np.linalg.eigvals(A - B @ K) self.checkPlaced(P_expected, P_placed)
def testPlace_varga_continuous(self, matarrayin): """ Check that we can place eigenvalues for dtime=False """ A = matarrayin([[1., -2.], [3., -4.]]) B = matarrayin([[5.], [7.]]) P = [-2., -2.] K = place_varga(A, B, P) P_placed = np.linalg.eigvals(A - B @ K) self.checkPlaced(P, P_placed) # Test that the dimension checks work. np.testing.assert_raises(ControlDimension, place, A[1:, :], B, P) np.testing.assert_raises(ControlDimension, place, A, B[1:, :], P) # Regression test against bug #177 # https://github.com/python-control/python-control/issues/177 A = matarrayin([[0, 1], [100, 0]]) B = matarrayin([[0], [1]]) P = matarrayin([-20 + 10 * 1j, -20 - 10 * 1j]) K = place_varga(A, B, P) P_placed = np.linalg.eigvals(A - B @ K) self.checkPlaced(P, P_placed)
def testPlace_varga_discrete_partial_eigs(self): """" Check that we can only assign a single eigenvalue in the discrete time case. """ # A matrix has eigenvalues at 1.0 and 0.5. Set alpha = 0.51, and # check that the eigenvalue at 0.5 is not moved. A = np.array([[1., 0], [0, 0.5]]) B = np.array([[5.], [7.]]) P = np.array([0.2, 0.6]) P_expected = np.array([0.5, 0.6]) alpha = 0.51 K = place_varga(A, B, P, dtime=True, alpha=alpha) P_placed = np.linalg.eigvals(A - B.dot(K)) P_expected.sort() P_placed.sort() np.testing.assert_array_almost_equal(P_expected, P_placed)
def testPlace_varga_continuous_partial_eigs(self, matarrayin): """ Check that we are able to use the alpha parameter to only place a subset of the eigenvalues, for the continous time case. """ # A matrix has eigenvalues at s=-1, and s=-2. Choose alpha = -1.5 # and check that eigenvalue at s=-2 stays put. A = matarrayin([[1., -2.], [3., -4.]]) B = matarrayin([[5.], [7.]]) P = matarrayin([-3.]) P_expected = np.array([-2.0, -3.0]) alpha = -1.5 K = place_varga(A, B, P, alpha=alpha) P_placed = np.linalg.eigvals(A - B @ K) # No guarantee of the ordering, so sort them self.checkPlaced(P_expected, P_placed)
def testPlace_varga_continuous_partial_eigs(self): """ Check that we are able to use the alpha parameter to only place a subset of the eigenvalues, for the continous time case. """ # A matrix has eigenvalues at s=-1, and s=-2. Choose alpha = -1.5 # and check that eigenvalue at s=-2 stays put. A = np.array([[1., -2.], [3., -4.]]) B = np.array([[5.], [7.]]) P = np.array([-3.]) P_expected = np.array([-2.0, -3.0]) alpha = -1.5 K = place_varga(A, B, P, alpha=alpha) P_placed = np.linalg.eigvals(A - B.dot(K)) # No guarantee of the ordering, so sort them P_expected.sort() P_placed.sort() np.testing.assert_array_almost_equal(P_expected, P_placed)