Skip to content

Commit b6713b8

Browse files
committed
Fix MIMO scalar state-space feedback
1 parent 146ccee commit b6713b8

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

control/statesp.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,8 @@ def feedback(self, other=1, sign=-1):
10031003
"""
10041004
# Convert the system to state space, if possible
10051005
try:
1006+
if np.isscalar(other) and self.ninputs == self.noutputs:
1007+
other = other * eye(self.ninputs)
10061008
other = _convert_to_statespace(other)
10071009
except:
10081010
pass

control/tests/bdalg_test.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,31 @@ def testSSSS2(self, tsys):
143143
0.142857142857143, -0.571428571428571, 0.857142857142857]])
144144
np.testing.assert_array_almost_equal(ans2.D, [[-0.285714285714286]])
145145

146+
def test_mimo_ss_scalar_feedback(self):
147+
"""MIMO state space system with scalar feedback block."""
148+
sys_static = StateSpace([], [], [], [[1, 0], [0, 2]])
149+
ans1 = feedback(sys_static)
150+
ans2 = feedback(sys_static, np.eye(2))
151+
np.testing.assert_array_almost_equal(ans1.D, ans2.D)
152+
153+
ans3 = feedback(sys_static, 2)
154+
ans4 = feedback(sys_static, 2 * np.eye(2))
155+
np.testing.assert_array_almost_equal(ans3.D, ans4.D)
156+
157+
sys_dynamic = StateSpace(
158+
[[-1, 0], [0, -2]], [[1, 0], [0, 1]],
159+
[[1, 0], [0, 1]], [[0, 0], [0, 0]])
160+
ans5 = feedback(sys_dynamic)
161+
ans6 = feedback(sys_dynamic, np.eye(2))
162+
np.testing.assert_array_almost_equal(ans5.A, ans6.A)
163+
np.testing.assert_array_almost_equal(ans5.B, ans6.B)
164+
np.testing.assert_array_almost_equal(ans5.C, ans6.C)
165+
np.testing.assert_array_almost_equal(ans5.D, ans6.D)
166+
167+
sys_nonsquare = StateSpace([], [], [], [[1, 2, 3], [4, 5, 6]])
168+
with pytest.raises(ValueError, match="compatible inputs/outputs"):
169+
feedback(sys_nonsquare)
170+
146171

147172
def testSSTF(self, tsys):
148173
"""State space system with transfer function feedback block."""

0 commit comments

Comments
 (0)