Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion control/statefbk.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def place_acker(A, B, poles):
pmat = pmat + p[n-i-1] * np.linalg.matrix_power(A, i)
K = np.linalg.solve(ct, pmat)

K = K[-1, :] # Extract the last row
K = K[-1:, :] # Extract the last row
return K


Expand Down
20 changes: 20 additions & 0 deletions control/tests/statefbk_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1272,3 +1272,23 @@ def test_create_statefbk_params(unicycle):
assert [k for k in clsys.params.keys()] == ['K', 'a', 'b']
assert clsys.params['a'] == 2
assert clsys.params['b'] == 1


@pytest.mark.parametrize('ny, nu', [(1, 1), (2, 2), (2, 1)])
@pytest.mark.parametrize(
'method', [
place, place_acker,
pytest.param(place_varga, marks=pytest.mark.slycot)])
def test_place_variants(ny, nu, method):
sys = ct.rss(states=2, inputs=nu, outputs=ny)
desired_poles = -np.arange(1, sys.nstates + 1, 1)

if method == place_acker and sys.ninputs != 1:
with pytest.raises(np.linalg.LinAlgError, match="must be square"):
K = method(sys.A, sys.B, desired_poles)
else:
K = method(sys.A, sys.B, desired_poles)

placed_poles = np.linalg.eigvals(sys.A - sys.B @ K)
np.testing.assert_array_almost_equal(
np.sort(desired_poles), np.sort(placed_poles))
2 changes: 1 addition & 1 deletion examples/cds110-L8a_maglev-limits.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@
"omega = np.linspace(0, 1e6, 100000)\n",
"for name, sys in zip(['C1', 'C2', 'C3'], [magS1, magS2, magS3]):\n",
" freqresp = ct.frequency_response(sys, omega)\n",
" bodeint = np.trapz(np.log(freqresp.magnitude), omega)\n",
" bodeint = np.trapezoid(np.log(freqresp.magnitude), omega)\n",
" print(\"Bode integral for\", name, \"=\", bodeint)\n",
"\n",
"print(\"pi * sum[ Re(pk) ]\", pi * np.sum(magP.poles()[magP.poles().real > 0]))"
Expand Down
2 changes: 1 addition & 1 deletion examples/cds112-L6_stochastic-linsys.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
"source": [
"# Calculate the sample properties and make sure they match\n",
"print(\"mean(V) [0.0] = \", np.mean(V))\n",
"print(\"cov(V) * dt [%0.3g] = \" % Q, np.round(np.cov(V), decimals=3) * dt)"
"print(\"cov(V) * dt [%0.3g] = \" % Q.item(), np.round(np.cov(V), decimals=3) * dt)"
]
},
{
Expand Down
56 changes: 24 additions & 32 deletions examples/stochresp.ipynb

Large diffs are not rendered by default.

Loading