def testLists(self): """Make sure that lists of various lengths work for operations""" sys1 = ctrl.tf([1, 1], [1, 2]) sys2 = ctrl.tf([1, 3], [1, 4]) sys3 = ctrl.tf([1, 5], [1, 6]) sys4 = ctrl.tf([1, 7], [1, 8]) sys5 = ctrl.tf([1, 9], [1, 0]) # Series sys1_2 = ctrl.series(sys1, sys2) np.testing.assert_array_almost_equal(sort(pole(sys1_2)), [-4., -2.]) np.testing.assert_array_almost_equal(sort(zero(sys1_2)), [-3., -1.]) sys1_3 = ctrl.series(sys1, sys2, sys3); np.testing.assert_array_almost_equal(sort(pole(sys1_3)), [-6., -4., -2.]) np.testing.assert_array_almost_equal(sort(zero(sys1_3)), [-5., -3., -1.]) sys1_4 = ctrl.series(sys1, sys2, sys3, sys4); np.testing.assert_array_almost_equal(sort(pole(sys1_4)), [-8., -6., -4., -2.]) np.testing.assert_array_almost_equal(sort(zero(sys1_4)), [-7., -5., -3., -1.]) sys1_5 = ctrl.series(sys1, sys2, sys3, sys4, sys5); np.testing.assert_array_almost_equal(sort(pole(sys1_5)), [-8., -6., -4., -2., -0.]) np.testing.assert_array_almost_equal(sort(zero(sys1_5)), [-9., -7., -5., -3., -1.]) # Parallel sys1_2 = ctrl.parallel(sys1, sys2) np.testing.assert_array_almost_equal(sort(pole(sys1_2)), [-4., -2.]) np.testing.assert_array_almost_equal(sort(zero(sys1_2)), sort(zero(sys1 + sys2))) sys1_3 = ctrl.parallel(sys1, sys2, sys3); np.testing.assert_array_almost_equal(sort(pole(sys1_3)), [-6., -4., -2.]) np.testing.assert_array_almost_equal(sort(zero(sys1_3)), sort(zero(sys1 + sys2 + sys3))) sys1_4 = ctrl.parallel(sys1, sys2, sys3, sys4); np.testing.assert_array_almost_equal(sort(pole(sys1_4)), [-8., -6., -4., -2.]) np.testing.assert_array_almost_equal(sort(zero(sys1_4)), sort(zero(sys1 + sys2 + sys3 + sys4))) sys1_5 = ctrl.parallel(sys1, sys2, sys3, sys4, sys5); np.testing.assert_array_almost_equal(sort(pole(sys1_5)), [-8., -6., -4., -2., -0.]) np.testing.assert_array_almost_equal(sort(zero(sys1_5)), sort(zero(sys1 + sys2 + sys3 + sys4 + sys5)))
def lima_zpk(sys): sys_poles = pole(sys) sys_zeros = zero(sys) sys_gain = dcgain(sys) / (np.prod(-sys_zeros) / np.prod(-sys_poles)) sys_gain = np.real(sys_gain) str_poles = '' str_zeros = '' for p in sys_poles: str_poles = str_poles + '(s + ' + "{:.2f}".format(-p) + ')' for z in sys_zeros: str_zeros = str_zeros + '(s + ' + "{:.2f}".format(-z) + ')' display(Math(r'\frac{' + "{:.2f}".format(sys_gain) + str_zeros + '}{' \ + str_poles + '}'))
def test_pole(self): sys = tf(126, [-1, 42]) np.testing.assert_allclose(sys.pole(), 42) np.testing.assert_allclose(pole(sys), 42)
def test_pole(self): sys = tf(126, [-1, 42]) np.testing.assert_equal(sys.pole(), 42) np.testing.assert_equal(pole(sys), 42)