示例#1
0
    def testObsvSISO(self, matarrayin):
        A = matarrayin([[1., 2.], [3., 4.]])
        C = matarrayin([[5., 7.]])
        Wotrue = np.array([[5., 7.], [26., 38.]])
        Wo = obsv(A, C)
        np.testing.assert_array_almost_equal(Wo, Wotrue)

        # Make sure default type values are correct
        assert ismatarrayout(Wo)
示例#2
0
    def testCtrbMIMO(self, matarrayin):
        A = matarrayin([[1., 2.], [3., 4.]])
        B = matarrayin([[5., 6.], [7., 8.]])
        Wctrue = np.array([[5., 6., 19., 22.], [7., 8., 43., 50.]])
        Wc = ctrb(A, B)
        np.testing.assert_array_almost_equal(Wc, Wctrue)

        # Make sure default type values are correct
        assert ismatarrayout(Wc)
示例#3
0
 def test_matlab_style_constructor(self):
     """Use (deprecated) matrix-style construction string"""
     with pytest.deprecated_call():
         sys = StateSpace("-1 1; 0 2", "0; 1", "1, 0", "0")
     assert sys.A.shape == (2, 2)
     assert sys.B.shape == (2, 1)
     assert sys.C.shape == (1, 2)
     assert sys.D.shape == (1, 1)
     for X in [sys.A, sys.B, sys.C, sys.D]:
         assert ismatarrayout(X)
示例#4
0
    def testCtrbSISO(self, matarrayin, matarrayout):
        A = matarrayin([[1., 2.], [3., 4.]])
        B = matarrayin([[5.], [7.]])
        Wctrue = np.array([[5., 19.], [7., 43.]])

        with check_deprecated_matrix():
            Wc = ctrb(A, B)
        assert ismatarrayout(Wc)

        np.testing.assert_array_almost_equal(Wc, Wctrue)
示例#5
0
    def testGramWc(self, matarrayin, matarrayout):
        A = matarrayin([[1., -2.], [3., -4.]])
        B = matarrayin([[5., 6.], [7., 8.]])
        C = matarrayin([[4., 5.], [6., 7.]])
        D = matarrayin([[13., 14.], [15., 16.]])
        sys = ss(A, B, C, D)
        Wctrue = np.array([[18.5, 24.5], [24.5, 32.5]])

        with check_deprecated_matrix():
            Wc = gram(sys, 'c')

        assert ismatarrayout(Wc)
        np.testing.assert_array_almost_equal(Wc, Wctrue)
示例#6
0
    def testPlace(self, matarrayin):
        # Matrices shamelessly stolen from scipy example code.
        A = matarrayin([[1.380, -0.2077, 6.715, -5.676],
                        [-0.5814, -4.290, 0, 0.6750],
                        [1.067, 4.273, -6.654, 5.893],
                        [0.0480, 4.273, 1.343, -2.104]])
        B = matarrayin([[0, 5.679], [1.136, 1.136], [0, 0], [-3.146, 0]])
        P = matarrayin([-0.5 + 1j, -0.5 - 1j, -5.0566, -8.6659])
        K = place(A, B, P)
        assert ismatarrayout(K)
        P_placed = np.linalg.eigvals(A - B @ K)
        self.checkPlaced(P, P_placed)

        # Test that the dimension checks work.
        with pytest.raises(ControlDimension):
            place(A[1:, :], B, P)
        with pytest.raises(ControlDimension):
            place(A, B[1:, :], P)

        # Check that we get an error if we ask for too many poles in the same
        # location. Here, rank(B) = 2, so lets place three at the same spot.
        P_repeated = matarrayin([-0.5, -0.5, -0.5, -8.6659])
        with pytest.raises(ValueError):
            place(A, B, P_repeated)