Skip to content

Commit e312569

Browse files
committed
LQE: added python 2 compatibility and unit test
1 parent 052edec commit e312569

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

control/statefbk.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,10 @@ def lqe(A, G, C, QN, RN, NN=None):
283283
#NG = G @ NN
284284

285285
#LT, P, E = lqr(A.T, C.T, G @ QN @ G.T, RN)
286-
P, E, LT = care(A.T, C.T, G @ QN @ G.T, RN)
286+
#P, E, LT = care(A.T, C.T, G @ QN @ G.T, RN)
287+
A, G, C = np.array(A, ndmin=2), np.array(G, ndmin=2), np.array(C, ndmin=2)
288+
QN, RN = np.array(QN, ndmin=2), np.array(RN, ndmin=2)
289+
P, E, LT = care(A.T, C.T, np.dot(np.dot(G, QN), G.T), RN)
287290
return _ssmatrix(LT.T), _ssmatrix(P), _ssmatrix(E)
288291

289292

control/tests/statefbk_test.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from __future__ import print_function
77
import unittest
88
import numpy as np
9-
from control.statefbk import ctrb, obsv, place, place_varga, lqr, gram, acker
9+
from control.statefbk import ctrb, obsv, place, place_varga, lqr, lqe, gram, acker
1010
from control.matlab import *
1111
from control.exception import slycot_check, ControlDimension
1212
from control.mateqn import care, dare
@@ -299,6 +299,20 @@ def test_LQR_3args(self):
299299
K, S, poles = lqr(sys, Q, R)
300300
self.check_LQR(K, S, poles, Q, R)
301301

302+
def check_LQE(self, L, P, poles, G, QN, RN):
303+
P_expected = np.array(np.sqrt(G*QN*G * RN))
304+
L_expected = P_expected / RN
305+
poles_expected = np.array([-L_expected], ndmin=2)
306+
np.testing.assert_array_almost_equal(P, P_expected)
307+
np.testing.assert_array_almost_equal(L, L_expected)
308+
np.testing.assert_array_almost_equal(poles, poles_expected)
309+
310+
@unittest.skipIf(not slycot_check(), "slycot not installed")
311+
def test_LQE(self):
312+
A, G, C, QN, RN = 0., .1, 1., 10., 2.
313+
L, P, poles = lqe(A, G, C, QN, RN)
314+
self.check_LQE(L, P, poles, G, QN, RN)
315+
302316
@unittest.skipIf(not slycot_check(), "slycot not installed")
303317
def test_care(self):
304318
#unit test for stabilizing and anti-stabilizing feedbacks

0 commit comments

Comments
 (0)