|
5 | 5 |
|
6 | 6 | importunittest
|
7 | 7 | importnumpyasnp
|
| 8 | +fromnumpyimportsort |
| 9 | +importcontrolasctrl |
8 | 10 | fromcontrol.xferfcnimportTransferFunction
|
9 | 11 | fromcontrol.statespimportStateSpace
|
10 | 12 | fromcontrol.bdalgimportfeedback
|
| 13 | +fromcontrol.ltiimportzero,pole |
11 | 14 |
|
12 | 15 | classTestFeedback(unittest.TestCase):
|
13 | 16 | """These are tests for the feedback function in bdalg.py. Currently, some
|
@@ -177,6 +180,63 @@ def testTFTF(self):
|
177 | 180 | np.testing.assert_array_almost_equal(ans2.num, [[[1.,4.,7.,6.]]])
|
178 | 181 | np.testing.assert_array_almost_equal(ans2.den, [[[1.,4.,9.,8.,5.]]])
|
179 | 182 |
|
| 183 | +deftestLists(self): |
| 184 | +"""Make sure that lists of various lengths work for operations""" |
| 185 | +sys1=ctrl.tf([1,1], [1,2]) |
| 186 | +sys2=ctrl.tf([1,3], [1,4]) |
| 187 | +sys3=ctrl.tf([1,5], [1,6]) |
| 188 | +sys4=ctrl.tf([1,7], [1,8]) |
| 189 | +sys5=ctrl.tf([1,9], [1,0]) |
| 190 | + |
| 191 | +# Series |
| 192 | +sys1_2=ctrl.series(sys1,sys2) |
| 193 | +np.testing.assert_array_almost_equal(sort(pole(sys1_2)), [-4.,-2.]) |
| 194 | +np.testing.assert_array_almost_equal(sort(zero(sys1_2)), [-3.,-1.]) |
| 195 | + |
| 196 | +sys1_3=ctrl.series(sys1,sys2,sys3); |
| 197 | +np.testing.assert_array_almost_equal(sort(pole(sys1_3)), |
| 198 | + [-6.,-4.,-2.]) |
| 199 | +np.testing.assert_array_almost_equal(sort(zero(sys1_3)), |
| 200 | + [-5.,-3.,-1.]) |
| 201 | + |
| 202 | +sys1_4=ctrl.series(sys1,sys2,sys3,sys4); |
| 203 | +np.testing.assert_array_almost_equal(sort(pole(sys1_4)), |
| 204 | + [-8.,-6.,-4.,-2.]) |
| 205 | +np.testing.assert_array_almost_equal(sort(zero(sys1_4)), |
| 206 | + [-7.,-5.,-3.,-1.]) |
| 207 | + |
| 208 | +sys1_5=ctrl.series(sys1,sys2,sys3,sys4,sys5); |
| 209 | +np.testing.assert_array_almost_equal(sort(pole(sys1_5)), |
| 210 | + [-8.,-6.,-4.,-2.,-0.]) |
| 211 | +np.testing.assert_array_almost_equal(sort(zero(sys1_5)), |
| 212 | + [-9.,-7.,-5.,-3.,-1.]) |
| 213 | + |
| 214 | +# Parallel |
| 215 | +sys1_2=ctrl.parallel(sys1,sys2) |
| 216 | +np.testing.assert_array_almost_equal(sort(pole(sys1_2)), [-4.,-2.]) |
| 217 | +np.testing.assert_array_almost_equal(sort(zero(sys1_2)), |
| 218 | +sort(zero(sys1+sys2))) |
| 219 | + |
| 220 | +sys1_3=ctrl.parallel(sys1,sys2,sys3); |
| 221 | +np.testing.assert_array_almost_equal(sort(pole(sys1_3)), |
| 222 | + [-6.,-4.,-2.]) |
| 223 | +np.testing.assert_array_almost_equal(sort(zero(sys1_3)), |
| 224 | +sort(zero(sys1+sys2+sys3))) |
| 225 | + |
| 226 | +sys1_4=ctrl.parallel(sys1,sys2,sys3,sys4); |
| 227 | +np.testing.assert_array_almost_equal(sort(pole(sys1_4)), |
| 228 | + [-8.,-6.,-4.,-2.]) |
| 229 | +np.testing.assert_array_almost_equal(sort(zero(sys1_4)), |
| 230 | +sort(zero(sys1+sys2+ |
| 231 | +sys3+sys4))) |
| 232 | + |
| 233 | + |
| 234 | +sys1_5=ctrl.parallel(sys1,sys2,sys3,sys4,sys5); |
| 235 | +np.testing.assert_array_almost_equal(sort(pole(sys1_5)), |
| 236 | + [-8.,-6.,-4.,-2.,-0.]) |
| 237 | +np.testing.assert_array_almost_equal(sort(zero(sys1_5)), |
| 238 | +sort(zero(sys1+sys2+ |
| 239 | +sys3+sys4+sys5))) |
180 | 240 | defsuite():
|
181 | 241 | returnunittest.TestLoader().loadTestsFromTestCase(TestFeedback)
|
182 | 242 |
|
|