7
7
import pytest
8
8
import itertools
9
9
import warnings
10
- from math import pi , atan
10
+ from math import pi
11
11
12
12
import control as ct
13
- from control import lqe , dlqe , poles , rss , ss , tf
13
+ from control import poles , rss , ss , tf
14
14
from control .exception import ControlDimension , ControlSlycot , \
15
15
ControlArgument , slycot_check
16
16
from control .mateqn import care , dare
@@ -57,6 +57,23 @@ def testCtrbT(self):
57
57
Wc = ctrb (A , B , t = t )
58
58
np .testing .assert_array_almost_equal (Wc , Wctrue )
59
59
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
+
60
77
def testObsvSISO (self ):
61
78
A = np .array ([[1. , 2. ], [3. , 4. ]])
62
79
C = np .array ([[5. , 7. ]])
@@ -79,6 +96,23 @@ def testObsvT(self):
79
96
Wo = obsv (A , C , t = t )
80
97
np .testing .assert_array_almost_equal (Wo , Wotrue )
81
98
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, C 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
+
82
116
def testCtrbObsvDuality (self ):
83
117
A = np .array ([[1.2 , - 2.3 ], [3.4 , - 4.5 ]])
84
118
B = np .array ([[5.8 , 6.9 ], [8. , 9.1 ]])
@@ -935,7 +969,6 @@ def unicycle_update(t, x, u, params):
935
969
states = ['x_' , 'y_' , 'theta_' ],
936
970
params = {'a' : 1 }) # only used for testing params
937
971
938
- from math import pi
939
972
940
973
@pytest .mark .parametrize ("method" , ['nearest' , 'linear' , 'cubic' ])
941
974
def test_gainsched_unicycle (unicycle , method ):
0 commit comments