|
| 1 | +from control.matlab import * |
| 2 | +import numpy as np |
| 3 | +from control.frdata import FRD as frd |
| 4 | + |
| 5 | +sys = ss(np.matrix('-2 0; 0 -1'), np.eye(2), np.eye(2), np.zeros((2,2))) |
| 6 | +print sys |
| 7 | + |
| 8 | +# convert to frd, 1 frequency |
| 9 | +fr = frd(sys, [1], smooth=False) |
| 10 | +print fr |
| 11 | + |
| 12 | +# the matching matrix |
| 13 | +frm = np.matrix([[0.4-0.2j, 0], [0, 0.5-0.5j]]) |
| 14 | +print frm |
| 15 | + |
| 16 | +# feedback of the system itself |
| 17 | +sys2 = sys.feedback(np.matrix('0 1; 3 0')) |
| 18 | +print sys2 |
| 19 | + |
| 20 | +# and the matching fr |
| 21 | +fr2 = frd(sys2, [1], smooth=False) |
| 22 | +print fr2 |
| 23 | + |
| 24 | +fr2b = fr.feedback([[0, 1], [3, 0]]) |
| 25 | +print fr2b |
| 26 | + |
| 27 | +# frequency response from the matrix should be |
| 28 | +frm*(np.eye(2)+np.matrix('0 1.0; 3 0')*frm).I |
| 29 | +print frm |
| 30 | + |
| 31 | +# one with 3 out and 2 inputs, 3 states |
| 32 | +bsys = ss(np.matrix('-2.0 0 0; 0 -1 1; 0 0 -3'), np.matrix('1.0 0; 0 0; 0 1'), np.eye(3), np.zeros((3,2))) |
| 33 | +print bsys |
| 34 | + |
| 35 | +# convert to frd, 1 frequency |
| 36 | +bfr = frd(bsys, [1]) |
| 37 | +print bfr |
| 38 | + |
| 39 | +# the matching matrix |
| 40 | +bfrm = np.matrix('0.4-0.2j 0;0 0.1-0.2j; 0 0.3-0.1j') |
| 41 | +print bfrm |
| 42 | + |
| 43 | +K = np.matrix('1 0.3 0; 0.1 0 0') |
| 44 | +bsys2 = bsys.feedback(K) |
| 45 | +print bsys2 |
| 46 | + |
| 47 | +# and the matching fr |
| 48 | +bfr2 = frd(bsys2, [1]) |
| 49 | +print bfr2 |
| 50 | + |
| 51 | +bfr2b = bfr.feedback( K) |
| 52 | +print bfr2b |
| 53 | + |
| 54 | +# frequency response from the matrix should be |
| 55 | +print bfrm*(np.eye(2)+K*bfrm).I |
0 commit comments