@@ -76,7 +76,7 @@ def series(sys1, *sysn):
7676 Raises
7777 ------
7878 ValueError
79- if `sys2.inputs ` does not equal `sys1.outputs `
79+ if `sys2.ninputs ` does not equal `sys1.noutputs `
8080 if `sys1.dt` is not compatible with `sys2.dt`
8181
8282 See Also
@@ -242,9 +242,9 @@ def feedback(sys1, sys2=1, sign=-1):
242242 if isinstance (sys2 , tf .TransferFunction ):
243243 sys1 = tf ._convert_to_transfer_function (sys1 )
244244 elif isinstance (sys2 , ss .StateSpace ):
245- sys1 = ss ._convertToStateSpace (sys1 )
245+ sys1 = ss ._convert_to_statespace (sys1 )
246246 elif isinstance (sys2 , frd .FRD ):
247- sys1 = frd ._convertToFRD (sys1 , sys2 .omega )
247+ sys1 = frd ._convert_to_FRD (sys1 , sys2 .omega )
248248 else : # sys2 is a scalar.
249249 sys1 = tf ._convert_to_transfer_function (sys1 )
250250 sys2 = tf ._convert_to_transfer_function (sys2 )
@@ -302,14 +302,16 @@ def connect(sys, Q, inputv, outputv):
302302 sys : StateSpace Transferfunction
303303 System to be connected
304304 Q : 2D array
305- Interconnection matrix. First column gives the input to be connected
306- second column gives the output to be fed into this input. Negative
307- values for the second column mean the feedback is negative, 0 means
308- no connection is made. Inputs and outputs are indexed starting at 1.
305+ Interconnection matrix. First column gives the input to be connected.
306+ The second column gives the index of an output that is to be fed into
307+ that input. Each additional column gives the index of an additional
308+ input that may be optionally added to that input. Negative
309+ values mean the feedback is negative. A zero value is ignored. Inputs
310+ and outputs are indexed starting at 1 to communicate sign information.
309311 inputv : 1D array
310- list of final external inputs
312+ list of final external inputs, indexed starting at 1
311313 outputv : 1D array
312- list of final external outputs
314+ list of final external outputs, indexed starting at 1
313315
314316 Returns
315317 -------
@@ -324,21 +326,47 @@ def connect(sys, Q, inputv, outputv):
324326 >>> Q = [[1, 2], [2, -1]] # negative feedback interconnection
325327 >>> sysc = connect(sys, Q, [2], [1, 2])
326328
329+ Notes
330+ -----
331+ The :func:`~control.interconnect` function in the
332+ :ref:`input/output systems <iosys-module>` module allows the use
333+ of named signals and provides an alternative method for
334+ interconnecting multiple systems.
335+
327336 """
337+ inputv , outputv , Q = np .asarray (inputv ), np .asarray (outputv ), np .asarray (Q )
338+ # check indices
339+ index_errors = (inputv - 1 > sys .ninputs ) | (inputv < 1 )
340+ if np .any (index_errors ):
341+ raise IndexError (
342+ "inputv index %s out of bounds" % inputv [np .where (index_errors )])
343+ index_errors = (outputv - 1 > sys .noutputs ) | (outputv < 1 )
344+ if np .any (index_errors ):
345+ raise IndexError (
346+ "outputv index %s out of bounds" % outputv [np .where (index_errors )])
347+ index_errors = (Q [:,0 :1 ] - 1 > sys .ninputs ) | (Q [:,0 :1 ] < 1 )
348+ if np .any (index_errors ):
349+ raise IndexError (
350+ "Q input index %s out of bounds" % Q [np .where (index_errors )])
351+ index_errors = (np .abs (Q [:,1 :]) - 1 > sys .noutputs )
352+ if np .any (index_errors ):
353+ raise IndexError (
354+ "Q output index %s out of bounds" % Q [np .where (index_errors )])
355+
328356 # first connect
329- K = np .zeros ((sys .inputs , sys .outputs ))
357+ K = np .zeros ((sys .ninputs , sys .noutputs ))
330358 for r in np .array (Q ).astype (int ):
331359 inp = r [0 ]- 1
332360 for outp in r [1 :]:
333- if outp > 0 and outp <= sys .outputs :
334- K [inp ,outp - 1 ] = 1.
335- elif outp < 0 and - outp >= - sys .outputs :
361+ if outp < 0 :
336362 K [inp ,- outp - 1 ] = - 1.
363+ elif outp > 0 :
364+ K [inp ,outp - 1 ] = 1.
337365 sys = sys .feedback (np .array (K ), sign = 1 )
338366
339367 # now trim
340- Ytrim = np .zeros ((len (outputv ), sys .outputs ))
341- Utrim = np .zeros ((sys .inputs , len (inputv )))
368+ Ytrim = np .zeros ((len (outputv ), sys .noutputs ))
369+ Utrim = np .zeros ((sys .ninputs , len (inputv )))
342370 for i ,u in enumerate (inputv ):
343371 Utrim [u - 1 ,i ] = 1.
344372 for i ,y in enumerate (outputv ):
0 commit comments