Skip to content

Commit be3bea5

Browse files
committed
Slight modifications to
Slight modifications to docstrings + unit tests
2 parents 52c5058 + 44dd3e6 commit be3bea5

2 files changed

Lines changed: 65 additions & 6 deletions

File tree

control/bdalg.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@
6161

6262
__all__ = ['series', 'parallel', 'negate', 'feedback', 'append', 'connect']
6363

64-
def series(sys1,*sysn):
65-
"""Return the series connection (... sys3 *) sys2 * sys1 for (... sys3 -->)--> sys1 --> sys2 -->.
64+
def series(sys1, *sysn):
65+
"""Return the series connection (... * sys3 *) sys2 * sys1
6666
6767
Parameters
6868
----------
@@ -98,7 +98,7 @@ def series(sys1,*sysn):
9898
Examples
9999
--------
100100
>>> sys3 = series(sys1, sys2) # Same as sys3 = sys2 * sys1.
101-
101+
>>> sys_final = series(sys1, sys2, sys3, sys4)
102102
>>> sys5 = series(sys1, sys2, sys3, sys4) # More syss
103103
104104
"""
@@ -107,7 +107,7 @@ def series(sys1,*sysn):
107107

108108
def parallel(sys1, *sysn):
109109
"""
110-
Return the parallel connection sys1 + sys2.
110+
Return the parallel connection sys1 + sys2 (+ sys3 + ...)
111111
112112
Parameters
113113
----------
@@ -143,7 +143,6 @@ def parallel(sys1, *sysn):
143143
Examples
144144
--------
145145
>>> sys3 = parallel(sys1, sys2) # Same as sys3 = sys1 + sys2.
146-
147146
>>> sys5 = parallel(sys1, sys2, sys3, sys4) # More syss
148147
149148
"""
@@ -251,7 +250,7 @@ def feedback(sys1, sys2=1, sign=-1):
251250
return sys1.feedback(sys2, sign)
252251

253252
def append(*sys):
254-
'''append(sys1, sys2, ... sysn)
253+
'''append(sys1, sys2, ..., sysn)
255254
256255
Group models by appending their inputs and outputs
257256

control/tests/bdalg_test.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55

66
import unittest
77
import numpy as np
8+
from numpy import sort
9+
import control as ctrl
810
from control.xferfcn import TransferFunction
911
from control.statesp import StateSpace
1012
from control.bdalg import feedback
13+
from control.lti import zero, pole
1114

1215
class TestFeedback(unittest.TestCase):
1316
"""These are tests for the feedback function in bdalg.py. Currently, some
@@ -177,6 +180,63 @@ def testTFTF(self):
177180
np.testing.assert_array_almost_equal(ans2.num, [[[1., 4., 7., 6.]]])
178181
np.testing.assert_array_almost_equal(ans2.den, [[[1., 4., 9., 8., 5.]]])
179182

183+
def testLists(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)))
180240
def suite():
181241
return unittest.TestLoader().loadTestsFromTestCase(TestFeedback)
182242

0 commit comments

Comments
 (0)