Skip to content

Commit f8ba0d9

Browse files
committed
test cases added for t < A.shape[0]
1 parent 49779aa commit f8ba0d9

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

control/statefbk.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,7 @@ def ctrb(A, B, t=None):
10271027
ctrb = np.zeros((n, t * m))
10281028
ctrb[:, :m] = bmat
10291029
for k in range(1, t):
1030-
ctrb[:, k * m:(k + 1) * m] = amat @ ctrb[:, (k - 1) * m:k * m]
1030+
ctrb[:, k * m:(k + 1) * m] = np.dot(amat, ctrb[:, (k - 1) * m:k * m])
10311031

10321032
return _ssmatrix(ctrb)
10331033

@@ -1070,7 +1070,7 @@ def obsv(A, C, t=None):
10701070
obsv[:p, :] = cmat
10711071

10721072
for k in range(1, t):
1073-
obsv[k * p:(k + 1) * p, :] = obsv[(k - 1) * p:k * p, :] @ amat
1073+
obsv[k * p:(k + 1) * p, :] = np.dot(obsv[(k - 1) * p:k * p, :], amat)
10741074

10751075
return _ssmatrix(obsv)
10761076

control/tests/statefbk_test.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ def testCtrbMIMO(self):
4949
Wc = ctrb(A, B)
5050
np.testing.assert_array_almost_equal(Wc, Wctrue)
5151

52+
def testCtrbT(self):
53+
A = np.array([[1., 2.], [3., 4.]])
54+
B = np.array([[5., 6.], [7., 8.]])
55+
t = 1
56+
Wctrue = np.array([[5., 6.], [7., 8.]])
57+
Wc = ctrb(A, B, t=t)
58+
np.testing.assert_array_almost_equal(Wc, Wctrue)
59+
5260
def testObsvSISO(self):
5361
A = np.array([[1., 2.], [3., 4.]])
5462
C = np.array([[5., 7.]])
@@ -62,6 +70,14 @@ def testObsvMIMO(self):
6270
Wotrue = np.array([[5., 6.], [7., 8.], [23., 34.], [31., 46.]])
6371
Wo = obsv(A, C)
6472
np.testing.assert_array_almost_equal(Wo, Wotrue)
73+
74+
def testObsvT(self):
75+
A = np.array([[1., 2.], [3., 4.]])
76+
C = np.array([[5., 6.], [7., 8.]])
77+
t = 1
78+
Wotrue = np.array([[5., 6.], [7., 8.]])
79+
Wo = obsv(A, C, t=t)
80+
np.testing.assert_array_almost_equal(Wo, Wotrue)
6581

6682
def testCtrbObsvDuality(self):
6783
A = np.array([[1.2, -2.3], [3.4, -4.5]])

0 commit comments

Comments
 (0)