Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit11bf14c

Browse files
authored
Merge pull request#220 from murrayrm/fix_minreal_test
update minreal unit test to use poles/zeros instead of num/den
2 parentscab7fa0 +99de25a commit11bf14c

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

‎control/tests/minreal_test.py

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,39 @@ def testMinrealBrute(self):
4343
ifs.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
foriinrange(m):
4954
forjinrange(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-
exceptExceptionase:
59-
# for larger systems, the tf minreal's
60-
# the original rss, but not the balanced one
61-
ifn<6:
62-
raisee
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+
forzeroinz1:
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+
forzeroinz2:
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
deftestMinrealSS(self):

‎control/xferfcn.py

Lines changed: 1 addition & 2 deletions
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)

[8]ページ先頭

©2009-2025 Movatter.jp