示例#1
0
    def test_scalar_static_gain(self):
        """Regression: can we create a scalar static gain?

        make sure StateSpace internals, specifically ABC matrix
        sizes, are OK for LTI operations
        """
        g1 = StateSpace([], [], [], [2])
        g2 = StateSpace([], [], [], [3])
        assert g1.dt == None
        assert g2.dt == None

        g3 = g1 * g2
        assert 6 == g3.D[0, 0]
        assert g3.dt == None

        g4 = g1 + g2
        assert 5 == g4.D[0, 0]
        assert g4.dt == None

        g5 = g1.feedback(g2)
        np.testing.assert_allclose(2. / 7, g5.D[0, 0])
        assert g5.dt == None

        g6 = g1.append(g2)
        np.testing.assert_allclose(np.diag([2, 3]), g6.D)
        assert g6.dt == None
示例#2
0
    def test_scalarStaticGain(self):
        """Regression: can we create a scalar static gain?"""
        g1=StateSpace([],[],[],[2])
        g2=StateSpace([],[],[],[3])

        # make sure StateSpace internals, specifically ABC matrix
        # sizes, are OK for LTI operations
        g3 = g1*g2
        self.assertEqual(6, g3.D[0,0])
        g4 = g1+g2
        self.assertEqual(5, g4.D[0,0])
        g5 = g1.feedback(g2)
        self.assertAlmostEqual(2./7, g5.D[0,0])
        g6 = g1.append(g2)
        np.testing.assert_array_equal(np.diag([2,3]),g6.D)
示例#3
0
    def test_matrixStaticGain(self):
        """Regression: can we create matrix static gains?"""
        d1 = np.matrix([[1,2,3],[4,5,6]])
        d2 = np.matrix([[7,8],[9,10],[11,12]])
        g1=StateSpace([],[],[],d1)

        # _remove_useless_states was making A = [[0]]
        self.assertEqual((0,0), g1.A.shape)

        g2=StateSpace([],[],[],d2)
        g3=StateSpace([],[],[],d2.T)

        h1 = g1*g2
        np.testing.assert_array_equal(d1*d2, h1.D)
        h2 = g1+g3
        np.testing.assert_array_equal(d1+d2.T, h2.D)
        h3 = g1.feedback(g2)
        np.testing.assert_array_almost_equal(solve(np.eye(2)+d1*d2,d1), h3.D)
        h4 = g1.append(g2)
        np.testing.assert_array_equal(block_diag(d1,d2),h4.D)
示例#4
0
 def testAppendTF(self):
     """Test appending a state-space system with a tf"""
     A1 = [[-2, 0.5, 0], [0.5, -0.3, 0], [0, 0, -0.1]]
     B1 = [[0.3, -1.3], [0.1, 0.], [1.0, 0.0]]
     C1 = [[0., 0.1, 0.0], [-0.3, -0.2, 0.0]]
     D1 = [[0., -0.8], [-0.3, 0.]]
     s = TransferFunction([1, 0], [1])
     h = 1/(s+1)/(s+2)
     sys1 = StateSpace(A1, B1, C1, D1)
     sys2 = _convertToStateSpace(h)
     sys3c = sys1.append(sys2)
     np.testing.assert_array_almost_equal(sys1.A, sys3c.A[:3,:3])
     np.testing.assert_array_almost_equal(sys1.B, sys3c.B[:3,:2])
     np.testing.assert_array_almost_equal(sys1.C, sys3c.C[:2,:3])
     np.testing.assert_array_almost_equal(sys1.D, sys3c.D[:2,:2])
     np.testing.assert_array_almost_equal(sys2.A, sys3c.A[3:,3:])
     np.testing.assert_array_almost_equal(sys2.B, sys3c.B[3:,2:])
     np.testing.assert_array_almost_equal(sys2.C, sys3c.C[2:,3:])
     np.testing.assert_array_almost_equal(sys2.D, sys3c.D[2:,2:])
     np.testing.assert_array_almost_equal(sys3c.A[:3,3:], np.zeros( (3, 2)) )
     np.testing.assert_array_almost_equal(sys3c.A[3:,:3], np.zeros( (2, 3)) )
示例#5
0
 def testAppendSS(self):
     """Test appending two state-space systems"""
     A1 = [[-2, 0.5, 0], [0.5, -0.3, 0], [0, 0, -0.1]]
     B1 = [[0.3, -1.3], [0.1, 0.], [1.0, 0.0]]
     C1 = [[0., 0.1, 0.0], [-0.3, -0.2, 0.0]]
     D1 = [[0., -0.8], [-0.3, 0.]]
     A2 = [[-1.]]
     B2 = [[1.2]]
     C2 = [[0.5]]
     D2 = [[0.4]]
     A3 = [[-2, 0.5, 0, 0], [0.5, -0.3, 0, 0], [0, 0, -0.1, 0],
           [0, 0, 0., -1.]]
     B3 = [[0.3, -1.3, 0], [0.1, 0., 0], [1.0, 0.0, 0], [0., 0, 1.2]]
     C3 = [[0., 0.1, 0.0, 0.0], [-0.3, -0.2, 0.0, 0.0], [0., 0., 0., 0.5]]
     D3 = [[0., -0.8, 0.], [-0.3, 0., 0.], [0., 0., 0.4]]
     sys1 = StateSpace(A1, B1, C1, D1)
     sys2 = StateSpace(A2, B2, C2, D2)
     sys3 = StateSpace(A3, B3, C3, D3)
     sys3c = sys1.append(sys2)
     np.testing.assert_array_almost_equal(sys3.A, sys3c.A)
     np.testing.assert_array_almost_equal(sys3.B, sys3c.B)
     np.testing.assert_array_almost_equal(sys3.C, sys3c.C)
     np.testing.assert_array_almost_equal(sys3.D, sys3c.D)