@@ -16,18 +16,19 @@ def test_reachable_form(self):
1616 coeffs = [1.0 , 2.0 , 3.0 , 4.0 , 1.0 ]
1717 A_true = np .polynomial .polynomial .polycompanion (coeffs )
1818 A_true = np .fliplr (np .rot90 (A_true ))
19- B_true = np .matrix ( " 1.0 0.0 0.0 0.0" ).T
20- C_true = np .matrix ( " 1.0 1.0 1.0 1.0" )
19+ B_true = np .array ([[ 1.0 , 0.0 , 0.0 , 0.0 ]] ).T
20+ C_true = np .array ([[ 1.0 , 1.0 , 1.0 , 1.0 ]] )
2121 D_true = 42.0
2222
2323 # Perform a coordinate transform with a random invertible matrix
24- T_true = np .matrix ([[- 0.27144004 , - 0.39933167 , 0.75634684 , 0.44135471 ],
25- [- 0.74855725 , - 0.39136285 , - 0.18142339 , - 0.50356997 ],
26- [- 0.40688007 , 0.81416369 , 0.38002113 , - 0.16483334 ],
27- [- 0.44769516 , 0.15654653 , - 0.50060858 , 0.72419146 ]])
28- A = np .linalg .solve (T_true , A_true )* T_true
24+ T_true = np .array (
25+ [[- 0.27144004 , - 0.39933167 , 0.75634684 , 0.44135471 ],
26+ [- 0.74855725 , - 0.39136285 , - 0.18142339 , - 0.50356997 ],
27+ [- 0.40688007 , 0.81416369 , 0.38002113 , - 0.16483334 ],
28+ [- 0.44769516 , 0.15654653 , - 0.50060858 , 0.72419146 ]])
29+ A = np .dot (np .linalg .solve (T_true , A_true ), T_true )
2930 B = np .linalg .solve (T_true , B_true )
30- C = C_true * T_true
31+ C = np . dot ( C_true , T_true )
3132 D = D_true
3233
3334 # Create a state space system and convert it to the reachable canonical form
@@ -44,9 +45,9 @@ def test_unreachable_system(self):
4445 """Test reachable canonical form with an unreachable system"""
4546
4647 # Create an unreachable system
47- A = np .matrix ( " 1.0 2.0 2.0; 4.0 5.0 5.0; 7.0 8.0 8.0" )
48- B = np .matrix ( " 1.0 1.0 1.0" ).T
49- C = np .matrix ( " 1.0 1.0 1.0" )
48+ A = np .array ([[ 1.0 , 2.0 , 2.0 ], [ 4.0 , 5.0 , 5.0 ], [ 7.0 , 8.0 , 8.0 ]] )
49+ B = np .array ([[ 1.0 , 1.0 , 1.0 ]] ).T
50+ C = np .array ([[ 1.0 , 1.0 , 1.0 ]] )
5051 D = 42.0
5152 sys = ss (A , B , C , D )
5253
@@ -57,19 +58,20 @@ def test_modal_form(self):
5758 """Test the modal canonical form"""
5859
5960 # Create a system in the modal canonical form
60- A_true = np .diag ([4.0 , 3.0 , 2.0 , 1.0 ]) # order from the largest to the smallest
61- B_true = np .matrix ( " 1.1 2.2 3.3 4.4" ).T
62- C_true = np .matrix ( " 1.3 1.4 1.5 1.6" )
61+ A_true = np .diag ([4.0 , 3.0 , 2.0 , 1.0 ]) # order from largest to smallest
62+ B_true = np .array ([[ 1.1 , 2.2 , 3.3 , 4.4 ]] ).T
63+ C_true = np .array ([[ 1.3 , 1.4 , 1.5 , 1.6 ]] )
6364 D_true = 42.0
6465
6566 # Perform a coordinate transform with a random invertible matrix
66- T_true = np .matrix ([[- 0.27144004 , - 0.39933167 , 0.75634684 , 0.44135471 ],
67- [- 0.74855725 , - 0.39136285 , - 0.18142339 , - 0.50356997 ],
68- [- 0.40688007 , 0.81416369 , 0.38002113 , - 0.16483334 ],
69- [- 0.44769516 , 0.15654653 , - 0.50060858 , 0.72419146 ]])
70- A = np .linalg .solve (T_true , A_true )* T_true
67+ T_true = np .array (
68+ [[- 0.27144004 , - 0.39933167 , 0.75634684 , 0.44135471 ],
69+ [- 0.74855725 , - 0.39136285 , - 0.18142339 , - 0.50356997 ],
70+ [- 0.40688007 , 0.81416369 , 0.38002113 , - 0.16483334 ],
71+ [- 0.44769516 , 0.15654653 , - 0.50060858 , 0.72419146 ]])
72+ A = np .dot (np .linalg .solve (T_true , A_true ), T_true )
7173 B = np .linalg .solve (T_true , B_true )
72- C = C_true * T_true
74+ C = np . dot ( C_true , T_true )
7375 D = D_true
7476
7577 # Create a state space system and convert it to the modal canonical form
@@ -90,18 +92,19 @@ def test_observable_form(self):
9092 coeffs = [1.0 , 2.0 , 3.0 , 4.0 , 1.0 ]
9193 A_true = np .polynomial .polynomial .polycompanion (coeffs )
9294 A_true = np .fliplr (np .flipud (A_true ))
93- B_true = np .matrix ( " 1.0 1.0 1.0 1.0" ).T
94- C_true = np .matrix ( " 1.0 0.0 0.0 0.0" )
95+ B_true = np .array ([[ 1.0 , 1.0 , 1.0 , 1.0 ]] ).T
96+ C_true = np .array ([[ 1.0 , 0.0 , 0.0 , 0.0 ]] )
9597 D_true = 42.0
9698
9799 # Perform a coordinate transform with a random invertible matrix
98- T_true = np .matrix ([[- 0.27144004 , - 0.39933167 , 0.75634684 , 0.44135471 ],
99- [- 0.74855725 , - 0.39136285 , - 0.18142339 , - 0.50356997 ],
100- [- 0.40688007 , 0.81416369 , 0.38002113 , - 0.16483334 ],
101- [- 0.44769516 , 0.15654653 , - 0.50060858 , 0.72419146 ]])
102- A = np .linalg .solve (T_true , A_true )* T_true
100+ T_true = np .array (
101+ [[- 0.27144004 , - 0.39933167 , 0.75634684 , 0.44135471 ],
102+ [- 0.74855725 , - 0.39136285 , - 0.18142339 , - 0.50356997 ],
103+ [- 0.40688007 , 0.81416369 , 0.38002113 , - 0.16483334 ],
104+ [- 0.44769516 , 0.15654653 , - 0.50060858 , 0.72419146 ]])
105+ A = np .dot (np .linalg .solve (T_true , A_true ), T_true )
103106 B = np .linalg .solve (T_true , B_true )
104- C = C_true * T_true
107+ C = np . dot ( C_true , T_true )
105108 D = D_true
106109
107110 # Create a state space system and convert it to the observable canonical form
@@ -118,11 +121,19 @@ def test_unobservable_system(self):
118121 """Test observable canonical form with an unobservable system"""
119122
120123 # Create an unobservable system
121- A = np .matrix ( " 1.0 2.0 2.0; 4.0 5.0 5.0; 7.0 8.0 8.0" )
122- B = np .matrix ( " 1.0 1.0 1.0" ).T
123- C = np .matrix ( " 1.0 1.0 1.0" )
124+ A = np .array ([[ 1.0 , 2.0 , 2.0 ], [ 4.0 , 5.0 , 5.0 ], [ 7.0 , 8.0 , 8.0 ]] )
125+ B = np .array ([[ 1.0 , 1.0 , 1.0 ]] ).T
126+ C = np .array ([[ 1.0 , 1.0 , 1.0 ]] )
124127 D = 42.0
125128 sys = ss (A , B , C , D )
126129
127130 # Check if an exception is raised
128131 np .testing .assert_raises (ValueError , canonical_form , sys , "observable" )
132+
133+
134+ def suite ():
135+ return unittest .TestLoader ().loadTestsFromTestCase (TestCanonical )
136+
137+
138+ if __name__ == "__main__" :
139+ unittest .main ()
0 commit comments