def test_common_den_nonproper(self): """ Test _common_den with order(num)>order(den) """ tf1 = TransferFunction([[[1., 2., 3.]], [[1., 2.]]], [[[1., -2.]], [[1., -3.]]]) tf2 = TransferFunction([[[1., 2.]], [[1., 2., 3.]]], [[[1., -2.]], [[1., -3.]]]) common_den_ref = np.array([[1., -5., 6.]]) np.testing.assert_raises(ValueError, tf1._common_den) np.testing.assert_raises(ValueError, tf2._common_den) _, den1, _ = tf1._common_den(allow_nonproper=True) np.testing.assert_array_almost_equal(den1, common_den_ref) _, den2, _ = tf2._common_den(allow_nonproper=True) np.testing.assert_array_almost_equal(den2, common_den_ref)
def test_common_den(self): """ Test the helper function to compute common denomitators.""" # _common_den() computes the common denominator per input/column. # The testing columns are: # 0: no common poles # 1: regular common poles # 2: poles with multiplicity, # 3: complex poles # 4: complex poles below threshold eps = np.finfo(float).eps tol_imag = np.sqrt(eps * 5 * 2 * 2) * 0.9 numin = [[[1.], [1.], [1.], [1.], [1.]], [[1.], [1.], [1.], [1.], [1.]]] denin = [ [ [1., 3., 2.], # 0: poles: [-1, -2] [1., 6., 11., 6.], # 1: poles: [-1, -2, -3] [1., 6., 11., 6.], # 2: poles: [-1, -2, -3] [1., 6., 11., 6.], # 3: poles: [-1, -2, -3] [1., 6., 11., 6.] ], # 4: poles: [-1, -2, -3], [ [1., 12., 47., 60.], # 0: poles: [-3, -4, -5] [1., 9., 26., 24.], # 1: poles: [-2, -3, -4] [1., 7., 16., 12.], # 2: poles: [-2, -2, -3] [1., 7., 17., 15.], # 3: poles: [-2+1J, -2-1J, -3], np.poly([-2 + tol_imag * 1J, -2 - tol_imag * 1J, -3]) ] ] numref = np.array([[[0., 0., 1., 12., 47., 60.], [0., 0., 0., 1., 4., 0.], [0., 0., 0., 1., 2., 0.], [0., 0., 0., 1., 4., 5.], [0., 0., 0., 1., 2., 0.]], [[0., 0., 0., 1., 3., 2.], [0., 0., 0., 1., 1., 0.], [0., 0., 0., 1., 1., 0.], [0., 0., 0., 1., 3., 2.], [0., 0., 0., 1., 1., 0.]]]) denref = np.array([[1., 15., 85., 225., 274., 120.], [1., 10., 35., 50., 24., 0.], [1., 8., 23., 28., 12., 0.], [1., 10., 40., 80., 79., 30.], [1., 8., 23., 28., 12., 0.]]) sys = TransferFunction(numin, denin) num, den, denorder = sys._common_den() np.testing.assert_array_almost_equal(num[:2, :, :], numref) np.testing.assert_array_almost_equal(num[2:, :, :], np.zeros( (3, 5, 6))) np.testing.assert_array_almost_equal(den, denref)