Skip to content

Commit 3215681

Browse files
committed
fix return shape for place_acker (python-control#1190)
1 parent 4242976 commit 3215681

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

control/statefbk.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def place_acker(A, B, poles):
251251
pmat = pmat + p[n-i-1] * np.linalg.matrix_power(A, i)
252252
K = np.linalg.solve(ct, pmat)
253253

254-
K = K[-1, :] # Extract the last row
254+
K = K[-1:, :] # Extract the last row
255255
return K
256256

257257

control/tests/statefbk_test.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,3 +1272,20 @@ def test_create_statefbk_params(unicycle):
12721272
assert [k for k in clsys.params.keys()] == ['K', 'a', 'b']
12731273
assert clsys.params['a'] == 2
12741274
assert clsys.params['b'] == 1
1275+
1276+
1277+
@pytest.mark.parametrize('ny, nu', [(1, 1), (2, 2), (2, 1)])
1278+
@pytest.mark.parametrize('method', [place, place_varga, place_acker])
1279+
def test_place_variants(ny, nu, method):
1280+
sys = ct.rss(states=2, inputs=nu, outputs=ny)
1281+
desired_poles = -np.arange(1, sys.nstates + 1, 1)
1282+
1283+
if method == place_acker and sys.ninputs != 1:
1284+
with pytest.raises(np.linalg.LinAlgError, match="must be square"):
1285+
K = method(sys.A, sys.B, desired_poles)
1286+
else:
1287+
K = method(sys.A, sys.B, desired_poles)
1288+
1289+
placed_poles = np.linalg.eigvals(sys.A - sys.B @ K)
1290+
np.testing.assert_array_almost_equal(
1291+
np.sort(desired_poles), np.sort(placed_poles))

0 commit comments

Comments
 (0)