Skip to content

Commit 99de25a

Browse files
committed
update minreal unit test to use poles/zeros instead of num/den
1 parent 87ec281 commit 99de25a

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

control/tests/minreal_test.py

+28-13
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,39 @@ def testMinrealBrute(self):
4343
if s.states > sr.states:
4444
self.nreductions += 1
4545
else:
46+
# Check to make sure that poles and zeros match
47+
48+
# For poles, just look at eigenvalues of A
4649
np.testing.assert_array_almost_equal(
4750
np.sort(eigvals(s.A)), np.sort(eigvals(sr.A)))
51+
52+
# For zeros, need to extract SISO systems
4853
for i in range(m):
4954
for j in range(p):
50-
ht1 = matlab.tf(
51-
matlab.ss(s.A, s.B[:,i], s.C[j,:], s.D[j,i]))
52-
ht2 = matlab.tf(
53-
matlab.ss(sr.A, sr.B[:,i], sr.C[j,:], sr.D[j,i]))
54-
try:
55-
self.assert_numden_almost_equal(
56-
ht1.num[0][0], ht2.num[0][0],
57-
ht1.den[0][0], ht2.den[0][0])
58-
except Exception as e:
59-
# for larger systems, the tf minreal's
60-
# the original rss, but not the balanced one
61-
if n < 6:
62-
raise e
55+
# Extract SISO dynamixs from input i to output j
56+
s1 = matlab.ss(s.A, s.B[:,i], s.C[j,:], s.D[j,i])
57+
s2 = matlab.ss(sr.A, sr.B[:,i], sr.C[j,:], sr.D[j,i])
58+
59+
# Check that the zeros match
60+
# Note: sorting doesn't work => have to do the hard way
61+
z1 = matlab.zero(s1)
62+
z2 = matlab.zero(s2)
63+
64+
# Start by making sure we have the same # of zeros
65+
self.assertEqual(len(z1), len(z2))
66+
67+
# Make sure all zeros in s1 are in s2
68+
for zero in z1:
69+
# Find the closest zero
70+
self.assertAlmostEqual(min(abs(z2 - zero)), 0.)
71+
72+
# Make sure all zeros in s2 are in s1
73+
for zero in z2:
74+
# Find the closest zero
75+
self.assertAlmostEqual(min(abs(z1 - zero)), 0.)
6376

77+
# Make sure that the number of systems reduced is as expected
78+
# (Need to update this number if you change the seed at top of file)
6479
self.assertEqual(self.nreductions, 2)
6580

6681
def testMinrealSS(self):

control/xferfcn.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1162,8 +1162,7 @@ def tf(*args):
11621162
tf2ss
11631163
11641164
Notes
1165-
--------
1166-
1165+
-----
11671166
``num[i][j]`` contains the polynomial coefficients of the numerator
11681167
for the transfer function from the (j+1)st input to the (i+1)st output.
11691168
``den[i][j]`` works the same way.

0 commit comments

Comments
 (0)