Skip to content

Commit b7e7ae9

Browse files
committed
Merge pull request python-control#53 from cwrowley/fix-lqr
Fix LQR for 3 arguments
2 parents 86ebb1c + 0f37e9f commit b7e7ae9

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

control/statefbk.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def lqr(*args, **keywords):
195195
#
196196

197197
# Get the system description
198-
if (len(args) < 4):
198+
if (len(args) < 3):
199199
raise ControlArgument("not enough input arguments")
200200

201201
try:

control/tests/statefbk_test.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,27 @@ def testAcker(self):
136136
np.testing.assert_array_almost_equal(np.sort(poles),
137137
np.sort(placed), decimal=4)
138138

139-
def suite():
139+
def check_LQR(self, K, S, poles, Q, R):
140+
S_expected = np.array(np.sqrt(Q * R))
141+
K_expected = S_expected / R
142+
poles_expected = np.array([-K_expected])
143+
np.testing.assert_array_almost_equal(S, S_expected)
144+
np.testing.assert_array_almost_equal(K, K_expected)
145+
np.testing.assert_array_almost_equal(poles, poles_expected)
146+
147+
148+
def test_LQR_integrator(self):
149+
A, B, Q, R = 0., 1., 10., 2.
150+
K, S, poles = lqr(A, B, Q, R)
151+
self.check_LQR(K, S, poles, Q, R)
152+
153+
def test_LQR_3args(self):
154+
sys = ss(0., 1., 1., 0.)
155+
Q, R = 10., 2.
156+
K, S, poles = lqr(sys, Q, R)
157+
self.check_LQR(K, S, poles, Q, R)
158+
159+
def test_suite():
140160
return unittest.TestLoader().loadTestsFromTestCase(TestStatefbk)
141161

142162
if __name__ == '__main__':

0 commit comments

Comments
 (0)