@@ -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 ):
0 commit comments