Skip to content

Commit 684fadb

Browse files
committed
add test case for lft for statespace model
1 parent bcf5382 commit 684fadb

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

control/tests/statesp_test.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,42 @@ def empty(shape):
448448
np.testing.assert_array_equal(empty((D.shape[0], 0)), g.C)
449449
np.testing.assert_array_equal(D, g.D)
450450

451+
def test_lft(self):
452+
""" compare lft function with matlab implementation"""
453+
# test case
454+
A = [[1, 2, 3],
455+
[1, 4, 5],
456+
[2, 3, 4]]
457+
B = [[0, 2],
458+
[5, 6],
459+
[5, 2]]
460+
C = [[1, 4, 5],
461+
[2, 3, 0]]
462+
D = [[0, 0],
463+
[3, 0]]
464+
P = StateSpace(A, B, C, D)
465+
Ak = [[0, 2, 3],
466+
[2, 3, 5],
467+
[2, 1, 9]]
468+
Bk = [[1, 1],
469+
[2, 3],
470+
[9, 4]]
471+
Ck = [[1, 4, 5],
472+
[2, 3, 6]]
473+
Dk = [[0, 2],
474+
[0, 0]]
475+
K = StateSpace(Ak, Bk, Ck, Dk)
476+
pk = P.lft(K, 2, 1)
477+
478+
# correct result (from matlab)
479+
Ak = [1, 2, 3, 4, 6, 12, 1, 4, 5, 17, 38, 61, 2, 3, 4, 9, 26, 37, 2, 3, 0, 3, 14, 18, 4, 6, 0, 8, 27, 35, 18, 27, 0, 29, 109, 144]
480+
Bk = [0, 10, 10, 7, 15, 58]
481+
Ck = [1, 4, 5, 0, 0, 0]
482+
Dk = [0]
483+
np.testing.assert_allclose(np.flatten(pk.A), Ak)
484+
np.testing.assert_allclose(np.flatten(pk.B), Bk)
485+
np.testing.assert_allclose(np.flatten(pk.C), Ck)
486+
np.testing.assert_allclose(np.flatten(pk.D), Dk)
451487

452488
class TestRss(unittest.TestCase):
453489
"""These are tests for the proper functionality of statesp.rss."""

0 commit comments

Comments
 (0)