当前位置: 首页>>代码示例>>Python>>正文


Python statesp.StateSpace类代码示例

本文整理汇总了Python中control.statesp.StateSpace的典型用法代码示例。如果您正苦于以下问题:Python StateSpace类的具体用法?Python StateSpace怎么用?Python StateSpace使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了StateSpace类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_evalfr

    def test_evalfr(self):
        """Evaluate the frequency response at one frequency."""

        A = [[-2, 0.5], [0.5, -0.3]]
        B = [[0.3, -1.3], [0.1, 0.]]
        C = [[0., 0.1], [-0.3, -0.2]]
        D = [[0., -0.8], [-0.3, 0.]]
        sys = StateSpace(A, B, C, D)

        resp = [[4.37636761487965e-05 - 0.0152297592997812j,
                 -0.792603938730853 + 0.0261706783369803j],
                [-0.331544857768052 + 0.0576105032822757j,
                 0.128919037199125 - 0.143824945295405j]]

        # Correct versions of the call
        np.testing.assert_almost_equal(evalfr(sys, 1j), resp)
        np.testing.assert_almost_equal(sys._evalfr(1.), resp)

        # Deprecated version of the call (should generate warning)
        import warnings
        with warnings.catch_warnings(record=True) as w:
            # Set up warnings filter to only show warnings in control module
            warnings.filterwarnings("ignore")
            warnings.filterwarnings("always", module="control")

            # Make sure that we get a pending deprecation warning
            sys.evalfr(1.)
            assert len(w) == 1
            assert issubclass(w[-1].category, PendingDeprecationWarning)
开发者ID:autodrive,项目名称:python-control,代码行数:29,代码来源:statesp_test.py

示例2: test_minrealStaticGain

 def test_minrealStaticGain(self):
     """Regression: minreal on static gain was failing"""
     g1 = StateSpace([],[],[],[1])
     g2 = g1.minreal()
     np.testing.assert_array_equal(g1.A, g2.A)
     np.testing.assert_array_equal(g1.B, g2.B)
     np.testing.assert_array_equal(g1.C, g2.C)
     np.testing.assert_array_equal(g1.D, g2.D)
开发者ID:cwrowley,项目名称:python-control,代码行数:8,代码来源:statesp_test.py

示例3: testZero

    def testZero(self):
        """Evaluate the zeros of a SISO system."""

        sys = StateSpace(self.sys1.A, [[3.], [-2.], [4.]], [[-1., 3., 2.]], [[-4.]])
        z = sys.zero()

        np.testing.assert_array_almost_equal(z, [4.26864638637134,
            -3.75932319318567 + 1.10087776649554j,
            -3.75932319318567 - 1.10087776649554j])
开发者ID:cwrowley,项目名称:python-control,代码行数:9,代码来源:statesp_test.py

示例4: testMIMO

 def testMIMO(self):
     sys = StateSpace([[-0.5, 0.0], [0.0, -1.0]], 
                      [[1.0, 0.0], [0.0, 1.0]], 
                      [[1.0, 0.0], [0.0, 1.0]], 
                      [[0.0, 0.0], [0.0, 0.0]])
     omega = np.logspace(-1, 2, 10)
     f1 = FRD(sys, omega)
     np.testing.assert_array_almost_equal(
         sys.freqresp([0.1, 1.0, 10])[0],
         f1.freqresp([0.1, 1.0, 10])[0])
     np.testing.assert_array_almost_equal(
         sys.freqresp([0.1, 1.0, 10])[1],
         f1.freqresp([0.1, 1.0, 10])[1])
开发者ID:Jeet1994,项目名称:python-control-code,代码行数:13,代码来源:frd_test.py

示例5: test_siso

   def test_siso(self):
      B = np.matrix('0;1')
      D = 0
      sys = StateSpace(self.A,B,self.C,D)

      # test frequency response
      frq=sys.freqresp(self.omega)

      # test bode plot
      bode(sys)

      # Convert to transfer function and test bode
      systf = tf(sys)
      bode(systf)
开发者ID:alchemyst,项目名称:python-control,代码行数:14,代码来源:freqresp_test.py

示例6: testMIMOfb2

 def testMIMOfb2(self):
     sys = StateSpace(np.matrix('-2.0 0 0; 0 -1 1; 0 0 -3'), 
                      np.matrix('1.0 0; 0 0; 0 1'), 
                      np.eye(3), np.zeros((3,2)))
     omega = np.logspace(-1, 2, 10)
     K = np.matrix('1 0.3 0; 0.1 0 0')
     f1 = FRD(sys, omega).feedback(K)
     f2 = FRD(sys.feedback(K), omega)
     np.testing.assert_array_almost_equal(
         f1.freqresp([0.1, 1.0, 10])[0],
         f2.freqresp([0.1, 1.0, 10])[0])
     np.testing.assert_array_almost_equal(
         f1.freqresp([0.1, 1.0, 10])[1],
         f2.freqresp([0.1, 1.0, 10])[1])
开发者ID:Jeet1994,项目名称:python-control-code,代码行数:14,代码来源:frd_test.py

示例7: test_scalarStaticGain

    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)
开发者ID:cwrowley,项目名称:python-control,代码行数:15,代码来源:statesp_test.py

示例8: testEvalFr

    def testEvalFr(self):
        """Evaluate the frequency response at one frequency."""

        A = [[-2, 0.5], [0.5, -0.3]]
        B = [[0.3, -1.3], [0.1, 0.]]
        C = [[0., 0.1], [-0.3, -0.2]]
        D = [[0., -0.8], [-0.3, 0.]]
        sys = StateSpace(A, B, C, D)

        resp = [[4.37636761487965e-05 - 0.0152297592997812j,
                 -0.792603938730853 + 0.0261706783369803j],
                [-0.331544857768052 + 0.0576105032822757j,
                 0.128919037199125 - 0.143824945295405j]]

        np.testing.assert_almost_equal(sys.evalfr(1.), resp)
开发者ID:cwrowley,项目名称:python-control,代码行数:15,代码来源:statesp_test.py

示例9: test_lft

    def test_lft(self):
        """ test lft function with result obtained from matlab implementation"""
        # test case
        A = [[1, 2, 3],
             [1, 4, 5],
             [2, 3, 4]]
        B = [[0, 2],
             [5, 6],
             [5, 2]]
        C = [[1, 4, 5],
             [2, 3, 0]]
        D = [[0, 0],
             [3, 0]]
        P = StateSpace(A, B, C, D)
        Ak = [[0, 2, 3],
              [2, 3, 5],
              [2, 1, 9]]
        Bk = [[1, 1],
              [2, 3],
              [9, 4]]
        Ck = [[1, 4, 5],
              [2, 3, 6]]
        Dk = [[0, 2],
              [0, 0]]
        K = StateSpace(Ak, Bk, Ck, Dk)

        # case 1
        pk = P.lft(K, 2, 1)
        Amatlab = [1, 2, 3, 4, 6, 12, 1, 4, 5, 17, 38, 61, 2, 3, 4, 9, 26, 37, 2, 3, 0, 3, 14, 18, 4, 6, 0, 8, 27, 35, 18, 27, 0, 29, 109, 144]
        Bmatlab = [0, 10, 10, 7, 15, 58]
        Cmatlab = [1, 4, 5, 0, 0, 0]
        Dmatlab = [0]
        np.testing.assert_allclose(np.array(pk.A).reshape(-1), Amatlab)
        np.testing.assert_allclose(np.array(pk.B).reshape(-1), Bmatlab)
        np.testing.assert_allclose(np.array(pk.C).reshape(-1), Cmatlab)
        np.testing.assert_allclose(np.array(pk.D).reshape(-1), Dmatlab)

        # case 2
        pk = P.lft(K)
        Amatlab = [1, 2, 3, 4, 6, 12, -3, -2, 5, 11, 14, 31, -2, -3, 4, 3, 2, 7, 0.6, 3.4, 5, -0.6, -0.4, 0, 0.8, 6.2, 10, 0.2, -4.2, -4, 7.4, 33.6, 45, -0.4, -8.6, -3]
        Bmatlab = []
        Cmatlab = []
        Dmatlab = []
        np.testing.assert_allclose(np.array(pk.A).reshape(-1), Amatlab)
        np.testing.assert_allclose(np.array(pk.B).reshape(-1), Bmatlab)
        np.testing.assert_allclose(np.array(pk.C).reshape(-1), Cmatlab)
        np.testing.assert_allclose(np.array(pk.D).reshape(-1), Dmatlab)
开发者ID:autodrive,项目名称:python-control,代码行数:47,代码来源:statesp_test.py

示例10: setUp

    def setUp(self):
        """Set up a MIMO system to test operations on."""

        # sys1: 3-states square system (2 inputs x 2 outputs)
        A322 = [[-3., 4., 2.],
                [-1., -3., 0.],
                [2., 5., 3.]]
        B322 = [[1., 4.],
                [-3., -3.],
                [-2., 1.]]
        C322 = [[4., 2., -3.],
                [1., 4., 3.]]
        D322 = [[-2., 4.],
                [0., 1.]]
        self.sys322 = StateSpace(A322, B322, C322, D322)

        # sys1: 2-states square system (2 inputs x 2 outputs)
        A222 = [[4., 1.],
                [2., -3]]
        B222 = [[5., 2.],
                [-3., -3.]]
        C222 = [[2., -4],
                [0., 1.]]
        D222 = [[3., 2.],
                [1., -1.]]
        self.sys222 = StateSpace(A222, B222, C222, D222)

        # sys3: 6 states non square system (2 inputs x 3 outputs)
        A623 = np.array([[1, 0, 0, 0, 0, 0],
                         [0, 1, 0, 0, 0, 0],
                         [0, 0, 3, 0, 0, 0],
                         [0, 0, 0, -4, 0, 0],
                         [0, 0, 0, 0, -1, 0],
                         [0, 0, 0, 0, 0, 3]])
        B623 = np.array([[0, -1],
                        [-1, 0],
                        [1, -1],
                        [0, 0],
                        [0, 1],
                        [-1, -1]])
        C623 = np.array([[1, 0, 0, 1, 0, 0],
                         [0, 1, 0, 1, 0, 1],
                         [0, 0, 1, 0, 0, 1]])
        D623 = np.zeros((3, 2))
        self.sys623 = StateSpace(A623, B623, C623, D623)
开发者ID:autodrive,项目名称:python-control,代码行数:45,代码来源:statesp_test.py

示例11: test_dcgain_integrator

    def test_dcgain_integrator(self):
        """DC gain when eigenvalue at DC returns appropriately sized array of nan"""
        # the SISO case is also tested in test_dc_gain_{cont,discr}
        import itertools
        # iterate over input and output sizes, and continuous (dt=None) and discrete (dt=True) time
        for inputs,outputs,dt in itertools.product(range(1,6),range(1,6),[None,True]):
            states = max(inputs,outputs)

            # a matrix that is singular at DC, and has no "useless" states as in _remove_useless_states
            a = np.triu(np.tile(2,(states,states)))
            # eigenvalues all +2, except for ...
            a[0,0] = 0 if dt is None else 1
            b = np.eye(max(inputs,states))[:states,:inputs]
            c = np.eye(max(outputs,states))[:outputs,:states]
            d = np.zeros((outputs,inputs))
            sys = StateSpace(a,b,c,d,dt)
            dc = np.squeeze(np.tile(np.nan,(outputs,inputs)))
            np.testing.assert_array_equal(dc, sys.dcgain())
开发者ID:cwrowley,项目名称:python-control,代码行数:18,代码来源:statesp_test.py

示例12: test_copy_constructor

    def test_copy_constructor(self):
        # Create a set of matrices for a simple linear system
        A = np.array([[-1]])
        B = np.array([[1]])
        C = np.array([[1]])
        D = np.array([[0]])

        # Create the first linear system and a copy
        linsys = StateSpace(A, B, C, D)
        cpysys = StateSpace(linsys)

        # Change the original A matrix
        A[0, 0] = -2
        np.testing.assert_array_equal(linsys.A, [[-1]]) # original value
        np.testing.assert_array_equal(cpysys.A, [[-1]]) # original value

        # Change the A matrix for the original system
        linsys.A[0, 0] = -3
        np.testing.assert_array_equal(cpysys.A, [[-1]]) # original value
开发者ID:python-control,项目名称:python-control,代码行数:19,代码来源:statesp_test.py

示例13: testMinreal

    def testMinreal(self):
        """Test a minreal model reduction"""
        #A = [-2, 0.5, 0; 0.5, -0.3, 0; 0, 0, -0.1]
        A = [[-2, 0.5, 0], [0.5, -0.3, 0], [0, 0, -0.1]]
        #B = [0.3, -1.3; 0.1, 0; 1, 0]
        B = [[0.3, -1.3], [0.1, 0.], [1.0, 0.0]]
        #C = [0, 0.1, 0; -0.3, -0.2, 0]
        C = [[0., 0.1, 0.0], [-0.3, -0.2, 0.0]]
        #D = [0 -0.8; -0.3 0]
        D = [[0., -0.8], [-0.3, 0.]]
        # sys = ss(A, B, C, D)

        sys = StateSpace(A, B, C, D)
        sysr = sys.minreal()
        self.assertEqual(sysr.states, 2)
        self.assertEqual(sysr.inputs, sys.inputs)
        self.assertEqual(sysr.outputs, sys.outputs)
        np.testing.assert_array_almost_equal(
            eigvals(sysr.A), [-2.136154, -0.1638459])
开发者ID:cwrowley,项目名称:python-control,代码行数:19,代码来源:statesp_test.py

示例14: test_matrixStaticGain

    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)
开发者ID:cwrowley,项目名称:python-control,代码行数:20,代码来源:statesp_test.py

示例15: testAppendTF

 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)) )
开发者ID:cwrowley,项目名称:python-control,代码行数:21,代码来源:statesp_test.py


注:本文中的control.statesp.StateSpace类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。