def test_size_mismatch(self):
        sys1 = ss2tf(rss(2, 2, 2))

        # Different number of inputs
        sys2 = ss2tf(rss(3, 1, 2))
        self.assertRaises(ValueError, TransferFunction.__add__, sys1, sys2)

        # Different number of outputs
        sys2 = ss2tf(rss(3, 2, 1))
        self.assertRaises(ValueError, TransferFunction.__add__, sys1, sys2)

        # Inputs and outputs don't match
        self.assertRaises(ValueError, TransferFunction.__mul__, sys2, sys1)

        # Feedback mismatch (MIMO not implemented)
        self.assertRaises(NotImplementedError,
                          TransferFunction.feedback, sys2, sys1)
Exemple #2
0
    def test_size_mismatch(self):
        sys1 = ss2tf(rss(2, 2, 2))

        # Different number of inputs
        sys2 = ss2tf(rss(3, 1, 2))
        self.assertRaises(ValueError, TransferFunction.__add__, sys1, sys2)

        # Different number of outputs
        sys2 = ss2tf(rss(3, 2, 1))
        self.assertRaises(ValueError, TransferFunction.__add__, sys1, sys2)

        # Inputs and outputs don't match
        self.assertRaises(ValueError, TransferFunction.__mul__, sys2, sys1)

        # Feedback mismatch (MIMO not implemented)
        self.assertRaises(NotImplementedError, TransferFunction.feedback, sys2,
                          sys1)
 def test_strictly_proper(self, strictly_proper):
     """Test that the strictly_proper argument returns a correct D."""
     for i in range(100):
         # The probability that drss(..., strictly_proper=False) returns an
         # all zero D 100 times in a row is 0.5**100 = 7.89e-31
         sys = rss(1, 1, 1, strictly_proper=strictly_proper)
         if np.all(sys.D == 0.) == strictly_proper:
             break
     assert np.all(sys.D == 0.) == strictly_proper
    def test_printing(self):
        # SISO, continuous time
        sys = ss2tf(rss(4, 1, 1))
        self.assertTrue(isinstance(str(sys), str))
        self.assertTrue(isinstance(sys._repr_latex_(), str))

        # SISO, discrete time
        sys = sample_system(sys, 1)
        self.assertTrue(isinstance(str(sys), str))
        self.assertTrue(isinstance(sys._repr_latex_(), str))
    def test_printing(self):
        """Print SISO"""
        sys = ss2tf(rss(4, 1, 1))
        assert isinstance(str(sys), str)
        assert isinstance(sys._repr_latex_(), str)

        # SISO, discrete time
        sys = sample_system(sys, 1)
        assert isinstance(str(sys), str)
        assert isinstance(sys._repr_latex_(), str)
Exemple #6
0
    def test_printing(self):
        # SISO, continuous time
        sys = ss2tf(rss(4, 1, 1))
        self.assertTrue(isinstance(str(sys), str))
        self.assertTrue(isinstance(sys._repr_latex_(), str))

        # SISO, discrete time
        sys = sample_system(sys, 1)
        self.assertTrue(isinstance(str(sys), str))
        self.assertTrue(isinstance(sys._repr_latex_(), str))
    def test_size_mismatch(self):
        """Test size mismacht"""
        sys1 = ss2tf(rss(2, 2, 2))

        # Different number of inputs
        sys2 = ss2tf(rss(3, 1, 2))
        with pytest.raises(ValueError):
            TransferFunction.__add__(sys1, sys2)

        # Different number of outputs
        sys2 = ss2tf(rss(3, 2, 1))
        with pytest.raises(ValueError):
            TransferFunction.__add__(sys1, sys2)

        # Inputs and outputs don't match
        with pytest.raises(ValueError):
            TransferFunction.__mul__(sys2, sys1)

        # Feedback mismatch (MIMO not implemented)
        with pytest.raises(NotImplementedError):
            TransferFunction.feedback(sys2, sys1)
Exemple #8
0
    def test_div(self):
        # Make sure that sampling times work correctly
        sys1 = TransferFunction([1., 3., 5], [1., 6., 2., -1])
        sys2 = TransferFunction([[[-1., 3.]]], [[[1., 0., -1.]]], True)
        sys3 = sys1 / sys2
        self.assertEqual(sys3.dt, True)

        sys2 = TransferFunction([[[-1., 3.]]], [[[1., 0., -1.]]], 0.5)
        sys3 = sys1 / sys2
        self.assertEqual(sys3.dt, 0.5)

        sys1 = TransferFunction([1., 3., 5], [1., 6., 2., -1], 0.1)
        self.assertRaises(ValueError, TransferFunction.__truediv__, sys1, sys2)

        sys1 = sample_system(rss(4, 1, 1), 0.5)
        sys3 = TransferFunction.__rtruediv__(sys2, sys1)
        self.assertEqual(sys3.dt, 0.5)
    def test_div(self):
        # Make sure that sampling times work correctly
        sys1 = TransferFunction([1., 3., 5], [1., 6., 2., -1])
        sys2 = TransferFunction([[[-1., 3.]]], [[[1., 0., -1.]]], True)
        sys3 = sys1 / sys2
        self.assertEqual(sys3.dt, True)

        sys2 = TransferFunction([[[-1., 3.]]], [[[1., 0., -1.]]], 0.5)
        sys3 = sys1 / sys2
        self.assertEqual(sys3.dt, 0.5)

        sys1 = TransferFunction([1., 3., 5], [1., 6., 2., -1], 0.1)
        self.assertRaises(ValueError, TransferFunction.__truediv__, sys1, sys2)

        sys1 = sample_system(rss(4, 1, 1), 0.5)
        sys3 = TransferFunction.__rtruediv__(sys2, sys1)
        self.assertEqual(sys3.dt, 0.5)
    def test_div(self):
        # Make sure that sampling times work correctly
        sys1 = TransferFunction([1., 3., 5], [1., 6., 2., -1], None)
        sys2 = TransferFunction([[[-1., 3.]]], [[[1., 0., -1.]]], True)
        sys3 = sys1 / sys2
        assert sys3.dt is True

        sys2 = TransferFunction([[[-1., 3.]]], [[[1., 0., -1.]]], 0.5)
        sys3 = sys1 / sys2
        assert sys3.dt == 0.5

        sys1 = TransferFunction([1., 3., 5], [1., 6., 2., -1], 0.1)
        with pytest.raises(ValueError):
            TransferFunction.__truediv__(sys1, sys2)

        sys1 = sample_system(rss(4, 1, 1), 0.5)
        sys3 = TransferFunction.__rtruediv__(sys2, sys1)
        assert sys3.dt == 0.5
    def test_indexing(self):
        tm = ss2tf(rss(5, 3, 3))

        # scalar indexing
        sys01 = tm[0, 1]
        np.testing.assert_array_almost_equal(sys01.num[0][0], tm.num[0][1])
        np.testing.assert_array_almost_equal(sys01.den[0][0], tm.den[0][1])

        # slice indexing
        sys = tm[:2, 1:3]
        np.testing.assert_array_almost_equal(sys.num[0][0], tm.num[0][1])
        np.testing.assert_array_almost_equal(sys.den[0][0], tm.den[0][1])
        np.testing.assert_array_almost_equal(sys.num[0][1], tm.num[0][2])
        np.testing.assert_array_almost_equal(sys.den[0][1], tm.den[0][2])
        np.testing.assert_array_almost_equal(sys.num[1][0], tm.num[1][1])
        np.testing.assert_array_almost_equal(sys.den[1][0], tm.den[1][1])
        np.testing.assert_array_almost_equal(sys.num[1][1], tm.num[1][2])
        np.testing.assert_array_almost_equal(sys.den[1][1], tm.den[1][2])
Exemple #12
0
    def test_indexing(self):
        tm = ss2tf(rss(5, 3, 3))

        # scalar indexing
        sys01 = tm[0, 1]
        np.testing.assert_array_almost_equal(sys01.num[0][0], tm.num[0][1])
        np.testing.assert_array_almost_equal(sys01.den[0][0], tm.den[0][1])

        # slice indexing
        sys = tm[:2, 1:3]
        np.testing.assert_array_almost_equal(sys.num[0][0], tm.num[0][1])
        np.testing.assert_array_almost_equal(sys.den[0][0], tm.den[0][1])
        np.testing.assert_array_almost_equal(sys.num[0][1], tm.num[0][2])
        np.testing.assert_array_almost_equal(sys.den[0][1], tm.den[0][2])
        np.testing.assert_array_almost_equal(sys.num[1][0], tm.num[1][1])
        np.testing.assert_array_almost_equal(sys.den[1][0], tm.den[1][1])
        np.testing.assert_array_almost_equal(sys.num[1][1], tm.num[1][2])
        np.testing.assert_array_almost_equal(sys.den[1][1], tm.den[1][2])
def test_latex_repr_testsize(editsdefaults):
    # _repr_latex_ returns None when size > maxsize
    from control import set_defaults

    maxsize = defaults['statesp.latex_maxsize']
    nstates = maxsize // 2
    ninputs = maxsize - nstates
    noutputs = ninputs

    assert nstates > 0
    assert ninputs > 0

    g = rss(nstates, ninputs, noutputs)
    assert isinstance(g._repr_latex_(), str)

    set_defaults('statesp', latex_maxsize=maxsize - 1)
    assert g._repr_latex_() is None

    set_defaults('statesp', latex_maxsize=-1)
    assert g._repr_latex_() is None

    gstatic = ss([], [], [], 1)
    assert gstatic._repr_latex_() is None
 def test_printing_mimo(self):
     """Print MIMO, continuous time"""
     sys = ss2tf(rss(4, 2, 3))
     assert isinstance(str(sys), str)
     assert isinstance(sys._repr_latex_(), str)
 def test_pole(self, states, outputs, inputs):
     """Test that the poles of rss outputs have a negative real part."""
     sys = rss(states, outputs, inputs)
     p = sys.pole()
     for z in p:
         assert z.real < 0
 def test_shape(self, states, outputs, inputs):
     """Test that rss outputs have the right state, input, and output size."""
     sys = rss(states, outputs, inputs)
     assert sys.states == states
     assert sys.inputs == inputs
     assert sys.outputs == outputs
 def test_printing_mimo(self):
     # MIMO, continuous time
     sys = ss2tf(rss(4, 2, 3))
     self.assertTrue(isinstance(str(sys), str))
     self.assertTrue(isinstance(sys._repr_latex_(), str))
Exemple #18
0
 def test_printing_mimo(self):
     # MIMO, continuous time
     sys = ss2tf(rss(4, 2, 3))
     self.assertTrue(isinstance(str(sys), str))
     self.assertTrue(isinstance(sys._repr_latex_(), str))