Skip to content

Commit d26d639

Browse files
author
Benjamin Greiner
committed
unit test for _common_den()
1 parent 1029410 commit d26d639

File tree

1 file changed

+53
-5
lines changed

1 file changed

+53
-5
lines changed

control/tests/xferfcn_test.py

+53-5
Original file line numberDiff line numberDiff line change
@@ -496,8 +496,57 @@ def test_freqresp_mimo(self):
496496
np.testing.assert_array_equal(omega, true_omega)
497497

498498
# Tests for TransferFunction.pole and TransferFunction.zero.
499-
500-
@unittest.skipIf(not slycot_check(), "slycot not installed")
499+
500+
def test_common_den(self):
501+
""" Test the helper function to compute common denomitators."""
502+
503+
# _common_den() computes the common denominator per input/column.
504+
# The testing columns are:
505+
# 0: no common poles
506+
# 1: regular common poles
507+
# 2: poles with multiplicity,
508+
# 3: complex poles
509+
# 4: complex poles below threshold
510+
511+
eps = np.finfo(float).eps
512+
tol_imag = np.sqrt(eps*5*2*2)*0.9
513+
514+
numin = [[[1.], [1.], [1.], [1.], [1.]],
515+
[[1.], [1.], [1.], [1.], [1.]]]
516+
denin = [[[1., 3., 2.], # 0: poles: [-1, -2]
517+
[1., 6., 11., 6.], # 1: poles: [-1, -2, -3]
518+
[1., 6., 11., 6.], # 2: poles: [-1, -2, -3]
519+
[1., 6., 11., 6.], # 3: poles: [-1, -2, -3]
520+
[1., 6., 11., 6.]], # 4: poles: [-1, -2, -3],
521+
[[1., 12., 47., 60.], # 0: poles: [-3, -4, -5]
522+
[1., 9., 26., 24.], # 1: poles: [-2, -3, -4]
523+
[1., 7., 16., 12.], # 2: poles: [-2, -2, -3]
524+
[1., 7., 17., 15.], # 3: poles: [-2+1J, -2-1J, -3],
525+
np.poly([-2 + tol_imag * 1J, -2 - tol_imag * 1J, -3])]]
526+
numref = np.array([
527+
[[0., 0., 1., 12., 47., 60.],
528+
[0., 0., 0., 1., 4., 0.],
529+
[0., 0., 0., 1., 2., 0.],
530+
[0., 0., 0., 1., 4., 5.],
531+
[0., 0., 0., 1., 2., 0.]],
532+
[[0., 0., 0., 1., 3., 2.],
533+
[0., 0., 0., 1., 1., 0.],
534+
[0., 0., 0., 1., 1., 0.],
535+
[0., 0., 0., 1., 3., 2.],
536+
[0., 0., 0., 1., 1., 0.]]])
537+
denref = np.array(
538+
[[1., 15., 85., 225., 274., 120.],
539+
[1., 10., 35., 50., 24., 0.],
540+
[1., 8., 23., 28., 12., 0.],
541+
[1., 10., 40., 80., 79., 30.],
542+
[1., 8., 23., 28., 12., 0.]])
543+
sys = TransferFunction(numin, denin)
544+
num, den, denorder = sys._common_den()
545+
np.testing.assert_array_almost_equal(num[:2, :, :], numref)
546+
np.testing.assert_array_almost_equal(num[2:, :, :],
547+
np.zeros((3, 5, 6)))
548+
np.testing.assert_array_almost_equal(den, denref)
549+
501550
def test_pole_mimo(self):
502551
"""Test for correct MIMO poles."""
503552

@@ -508,13 +557,12 @@ def test_pole_mimo(self):
508557

509558
np.testing.assert_array_almost_equal(p, [-2., -2., -7., -3., -2.])
510559

511-
@unittest.skipIf(not slycot_check(), "slycot not installed")
512560
def test_double_cancelling_poles_siso(self):
513-
561+
514562
H = TransferFunction([1, 1], [1, 2, 1])
515563
p = H.pole()
516564
np.testing.assert_array_almost_equal(p, [-1, -1])
517-
565+
518566
# Tests for TransferFunction.feedback
519567
def test_feedback_siso(self):
520568
"""Test for correct SISO transfer function feedback."""

0 commit comments

Comments
 (0)