@@ -57,6 +57,23 @@ def testCtrbT(self):
5757 Wc = ctrb (A , B , t = t )
5858 np .testing .assert_array_almost_equal (Wc , Wctrue )
5959
60+ def testCtrbNdim1 (self ):
61+ # gh-1097: treat 1-dim B as nx1
62+ A = np .array ([[1. , 2. ], [3. , 4. ]])
63+ B = np .array ([5. , 7. ])
64+ Wctrue = np .array ([[5. , 19. ], [7. , 43. ]])
65+ Wc = ctrb (A , B )
66+ np .testing .assert_array_almost_equal (Wc , Wctrue )
67+
68+ def testCtrbRejectMismatch (self ):
69+ # gh-1097: check A, B for compatible shapes
70+ with pytest .raises (ControlDimension , match = 'A must be a square matrix' ):
71+ ctrb ([[1 ,2 ]],[1 ])
72+ with pytest .raises (ControlDimension , match = 'Incompatible dimensions of B matrix' ):
73+ ctrb ([[1 ,2 ],[2 ,3 ]], 1 )
74+ with pytest .raises (ControlDimension , match = 'Incompatible dimensions of B matrix' ):
75+ ctrb ([[1 ,2 ],[2 ,3 ]], [[1 ,2 ]])
76+
6077 def testObsvSISO (self ):
6178 A = np .array ([[1. , 2. ], [3. , 4. ]])
6279 C = np .array ([[5. , 7. ]])
@@ -79,6 +96,23 @@ def testObsvT(self):
7996 Wo = obsv (A , C , t = t )
8097 np .testing .assert_array_almost_equal (Wo , Wotrue )
8198
99+ def testObsvNdim1 (self ):
100+ # gh-1097: treat 1-dim C as 1xn
101+ A = np .array ([[1. , 2. ], [3. , 4. ]])
102+ C = np .array ([5. , 7. ])
103+ Wotrue = np .array ([[5. , 7. ], [26. , 38. ]])
104+ Wo = obsv (A , C )
105+ np .testing .assert_array_almost_equal (Wo , Wotrue )
106+
107+ def testObsvRejectMismatch (self ):
108+ # gh-1097: check A, B for compatible shapes
109+ with pytest .raises (ControlDimension , match = 'A must be a square matrix' ):
110+ obsv ([[1 ,2 ]],[1 ])
111+ with pytest .raises (ControlDimension , match = 'Incompatible dimensions of C matrix' ):
112+ obsv ([[1 ,2 ],[2 ,3 ]], 1 )
113+ with pytest .raises (ControlDimension , match = 'Incompatible dimensions of C matrix' ):
114+ obsv ([[1 ,2 ],[2 ,3 ]], [[1 ],[2 ]])
115+
82116 def testCtrbObsvDuality (self ):
83117 A = np .array ([[1.2 , - 2.3 ], [3.4 , - 4.5 ]])
84118 B = np .array ([[5.8 , 6.9 ], [8. , 9.1 ]])
0 commit comments