|
2 | 2 |
|
3 | 3 | from statefbk import ctrb, obsv, place, lqr, gram |
4 | 4 | from matlab import * |
5 | | -import numpy as N |
| 5 | +import numpy as np |
6 | 6 | import unittest |
7 | 7 |
|
8 | 8 | class TestStatefbk(unittest.TestCase): |
9 | 9 | def testCtrbSISO(self): |
10 | | - A = N.matrix("1. 2.; 3. 4.") |
11 | | - B = N.matrix("5.; 7.") |
12 | | - Wctrue = N.matrix("5. 19.; 7. 43.") |
| 10 | + A = np.matrix("1. 2.; 3. 4.") |
| 11 | + B = np.matrix("5.; 7.") |
| 12 | + Wctrue = np.matrix("5. 19.; 7. 43.") |
13 | 13 | Wc = ctrb(A,B) |
14 | | - N.testing.assert_array_almost_equal(Wc, Wctrue) |
| 14 | + np.testing.assert_array_almost_equal(Wc, Wctrue) |
15 | 15 |
|
16 | 16 | def testCtrbMIMO(self): |
17 | | - A = N.matrix("1. 2.; 3. 4.") |
18 | | - B = N.matrix("5. 6.; 7. 8.") |
19 | | - Wctrue = N.matrix("5. 6. 19. 22.; 7. 8. 43. 50.") |
| 17 | + A = np.matrix("1. 2.; 3. 4.") |
| 18 | + B = np.matrix("5. 6.; 7. 8.") |
| 19 | + Wctrue = np.matrix("5. 6. 19. 22.; 7. 8. 43. 50.") |
20 | 20 | Wc = ctrb(A,B) |
21 | | - N.testing.assert_array_almost_equal(Wc, Wctrue) |
| 21 | + np.testing.assert_array_almost_equal(Wc, Wctrue) |
22 | 22 |
|
23 | 23 | def testObsvSISO(self): |
24 | | - A = N.matrix("1. 2.; 3. 4.") |
25 | | - C = N.matrix("5. 7.") |
26 | | - Wotrue = N.matrix("5. 7.; 26. 38.") |
| 24 | + A = np.matrix("1. 2.; 3. 4.") |
| 25 | + C = np.matrix("5. 7.") |
| 26 | + Wotrue = np.matrix("5. 7.; 26. 38.") |
27 | 27 | Wo = obsv(A,C) |
28 | | - N.testing.assert_array_almost_equal(Wo, Wotrue) |
| 28 | + np.testing.assert_array_almost_equal(Wo, Wotrue) |
29 | 29 |
|
30 | 30 | def testObsvMIMO(self): |
31 | | - A = N.matrix("1. 2.; 3. 4.") |
32 | | - C = N.matrix("5. 6.; 7. 8.") |
33 | | - Wotrue = N.matrix("5. 6.; 7. 8.; 23. 34.; 31. 46.") |
| 31 | + A = np.matrix("1. 2.; 3. 4.") |
| 32 | + C = np.matrix("5. 6.; 7. 8.") |
| 33 | + Wotrue = np.matrix("5. 6.; 7. 8.; 23. 34.; 31. 46.") |
34 | 34 | Wo = obsv(A,C) |
35 | | - N.testing.assert_array_almost_equal(Wo, Wotrue) |
| 35 | + np.testing.assert_array_almost_equal(Wo, Wotrue) |
36 | 36 |
|
37 | 37 | def testCtrbObsvDuality(self): |
38 | | - A = N.matrix("1.2 -2.3; 3.4 -4.5") |
39 | | - B = N.matrix("5.8 6.9; 8. 9.1") |
| 38 | + A = np.matrix("1.2 -2.3; 3.4 -4.5") |
| 39 | + B = np.matrix("5.8 6.9; 8. 9.1") |
40 | 40 | Wc = ctrb(A,B); |
41 | | - A = N.transpose(A) |
42 | | - C = N.transpose(B) |
43 | | - Wo = N.transpose(obsv(A,C)); |
44 | | - N.testing.assert_array_almost_equal(Wc,Wo) |
| 41 | + A = np.transpose(A) |
| 42 | + C = np.transpose(B) |
| 43 | + Wo = np.transpose(obsv(A,C)); |
| 44 | + np.testing.assert_array_almost_equal(Wc,Wo) |
45 | 45 |
|
46 | 46 | def testGramWc(self): |
47 | | - A = N.matrix("1. -2.; 3. -4.") |
48 | | - B = N.matrix("5. 6.; 7. 8.") |
49 | | - C = N.matrix("4. 5.; 6. 7.") |
50 | | - D = N.matrix("13. 14.; 15. 16.") |
| 47 | + A = np.matrix("1. -2.; 3. -4.") |
| 48 | + B = np.matrix("5. 6.; 7. 8.") |
| 49 | + C = np.matrix("4. 5.; 6. 7.") |
| 50 | + D = np.matrix("13. 14.; 15. 16.") |
51 | 51 | # sys = ss(A, B, C, D) |
52 | 52 | sys = 1. |
53 | | - Wctrue = N.matrix("18.5 24.5; 24.5 32.5") |
| 53 | + Wctrue = np.matrix("18.5 24.5; 24.5 32.5") |
54 | 54 | Wc = gram(sys,'c') |
55 | | - N.testing.assert_array_almost_equal(Wc, Wctrue) |
| 55 | + np.testing.assert_array_almost_equal(Wc, Wctrue) |
56 | 56 |
|
57 | 57 | def testGramWo(self): |
58 | | - A = N.matrix("1. -2.; 3. -4.") |
59 | | - B = N.matrix("5. 6.; 7. 8.") |
60 | | - C = N.matrix("4. 5.; 6. 7.") |
61 | | - D = N.matrix("13. 14.; 15. 16.") |
| 58 | + A = np.matrix("1. -2.; 3. -4.") |
| 59 | + B = np.matrix("5. 6.; 7. 8.") |
| 60 | + C = np.matrix("4. 5.; 6. 7.") |
| 61 | + D = np.matrix("13. 14.; 15. 16.") |
62 | 62 | sys = ss(A, B, C, D) |
63 | 63 | sys = 1. |
64 | | - Wotrue = N.matrix("257.5 -94.5; -94.5 56.5") |
| 64 | + Wotrue = np.matrix("257.5 -94.5; -94.5 56.5") |
65 | 65 | Wo = gram(sys,'o') |
66 | | - N.testing.assert_array_almost_equal(Wo, Wotrue) |
| 66 | + np.testing.assert_array_almost_equal(Wo, Wotrue) |
67 | 67 |
|
68 | 68 | if __name__ == '__main__': |
69 | 69 | unittest.main() |
0 commit comments