3030 ['u' , 'y' , 2 , [[1 , 0 ], [0 , 1 ]] ],
3131 [['r' , '-y' ], ['e' ], 2 , [[1 , 0 , - 1 , 0 ], [0 , 1 , 0 , - 1 ]] ],
3232])
33- def test_summation_block (inputs , output , dimension , D ):
33+ def test_summing_junction (inputs , output , dimension , D ):
3434 ninputs = 1 if isinstance (inputs , str ) else \
3535 inputs if isinstance (inputs , int ) else len (inputs )
36- sum = ct .summation_block (
36+ sum = ct .summing_junction (
3737 inputs = inputs , output = output , dimension = dimension )
3838 dim = 1 if dimension is None else dimension
3939 np .testing .assert_array_equal (sum .A , np .ndarray ((0 , 0 )))
@@ -45,15 +45,15 @@ def test_summation_block(inputs, output, dimension, D):
4545def test_summation_exceptions ():
4646 # Bad input description
4747 with pytest .raises (ValueError , match = "could not parse input" ):
48- sumblk = ct .summation_block (None , 'y' )
48+ sumblk = ct .summing_junction (None , 'y' )
4949
5050 # Bad output description
5151 with pytest .raises (ValueError , match = "could not parse output" ):
52- sumblk = ct .summation_block ('u' , None )
52+ sumblk = ct .summing_junction ('u' , None )
5353
5454 # Bad input dimension
5555 with pytest .raises (ValueError , match = "unrecognized dimension" ):
56- sumblk = ct .summation_block ('u' , 'y' , dimension = False )
56+ sumblk = ct .summing_junction ('u' , 'y' , dimension = False )
5757
5858
5959def test_interconnect_implicit ():
@@ -83,8 +83,8 @@ def test_interconnect_implicit():
8383 np .testing .assert_almost_equal (Tio_exp .C , Tss .C )
8484 np .testing .assert_almost_equal (Tio_exp .D , Tss .D )
8585
86- # Construct the interconnection via a summation block
87- sumblk = ct .summation_block (inputs = ['r' , '-y' ], output = 'e' , name = "sum" )
86+ # Construct the interconnection via a summing junction
87+ sumblk = ct .summing_junction (inputs = ['r' , '-y' ], output = 'e' , name = "sum" )
8888 Tio_sum = ct .interconnect (
8989 (C , P , sumblk ), inplist = ['r' ], outlist = ['y' ])
9090
@@ -108,6 +108,17 @@ def test_interconnect_implicit():
108108 np .testing .assert_almost_equal (Tio_sum .C , Tss .C )
109109 np .testing .assert_almost_equal (Tio_sum .D , Tss .D )
110110
111+ # TODO: interconnect a MIMO system using implicit connections
112+ # P = control.ss2io(
113+ # control.rss(2, 2, 2, strictly_proper=True),
114+ # input_prefix='u', output_prefix='y', name='P')
115+ # C = control.ss2io(
116+ # control.rss(2, 2, 2),
117+ # input_prefix='e', output_prefix='u', name='C')
118+ # sumblk = control.summing_junction(
119+ # inputs=['r', '-y'], output='e', dimension=2)
120+ # S = control.interconnect([P, C, sumblk], inplist='r', outlist='y')
121+
111122 # Make sure that repeated inplist/outlist names generate an error
112123 # Input not unique
113124 Cbad = ct .tf2io (ct .tf (10 , [1 , 1 ]), inputs = 'r' , outputs = 'x' , name = 'C' )
@@ -129,3 +140,35 @@ def test_interconnect_implicit():
129140 with pytest .raises (ValueError , match = "could not find" ):
130141 Tio_sum = ct .interconnect (
131142 (C , P , sumblk ), inplist = ['r' ], outlist = ['x' ])
143+
144+ def test_interconnect_docstring ():
145+ """Test the examples from the interconnect() docstring"""
146+
147+ # MIMO interconnection (note: use [C, P] instead of [P, C] for state order)
148+ P = ct .LinearIOSystem (
149+ ct .rss (2 , 2 , 2 , strictly_proper = True ), name = 'P' )
150+ C = ct .LinearIOSystem (ct .rss (2 , 2 , 2 ), name = 'C' )
151+ T = ct .interconnect (
152+ [C , P ],
153+ connections = [
154+ ['P.u[0]' , 'C.y[0]' ], ['P.u[1]' , 'C.y[1]' ],
155+ ['C.u[0]' , '-P.y[0]' ], ['C.u[1]' , '-P.y[1]' ]],
156+ inplist = ['C.u[0]' , 'C.u[1]' ],
157+ outlist = ['P.y[0]' , 'P.y[1]' ],
158+ )
159+ T_ss = ct .feedback (P * C , ct .ss ([], [], [], np .eye (2 )))
160+ np .testing .assert_almost_equal (T .A , T_ss .A )
161+ np .testing .assert_almost_equal (T .B , T_ss .B )
162+ np .testing .assert_almost_equal (T .C , T_ss .C )
163+ np .testing .assert_almost_equal (T .D , T_ss .D )
164+
165+ # Implicit interconnection (note: use [C, P, sumblk] for proper state order)
166+ P = ct .tf2io (ct .tf (1 , [1 , 0 ]), inputs = 'u' , outputs = 'y' )
167+ C = ct .tf2io (ct .tf (10 , [1 , 1 ]), inputs = 'e' , outputs = 'u' )
168+ sumblk = ct .summing_junction (inputs = ['r' , '-y' ], output = 'e' )
169+ T = ct .interconnect ([C , P , sumblk ], inplist = 'r' , outlist = 'y' )
170+ T_ss = ct .feedback (P * C , 1 )
171+ np .testing .assert_almost_equal (T .A , T_ss .A )
172+ np .testing .assert_almost_equal (T .B , T_ss .B )
173+ np .testing .assert_almost_equal (T .C , T_ss .C )
174+ np .testing .assert_almost_equal (T .D , T_ss .D )
0 commit comments