Skip to content

Commit ea7d3ed

Browse files
committed
Update split_tf and combine_tf docstrings + combine_tf kwargs
1 parent 9ca6833 commit ea7d3ed

3 files changed

Lines changed: 49 additions & 37 deletions

File tree

control/bdalg.py

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def parallel(sys1, *sysn, **kwargs):
164164
or `y`). See :class:`InputOutputSystem` for more information.
165165
states : str, or list of str, optional
166166
List of names for system states. If not given, state names will be
167-
of of the form `x[i]` for interconnections of linear systems or
167+
of the form `x[i]` for interconnections of linear systems or
168168
'<subsys_name>.<state_name>' for interconnected nonlinear systems.
169169
name : string, optional
170170
System name (used for specifying signals). If unspecified, a generic
@@ -511,7 +511,7 @@ def connect(sys, Q, inputv, outputv):
511511

512512
return Ytrim * sys * Utrim
513513

514-
def combine_tf(tf_array):
514+
def combine_tf(tf_array, **kwargs):
515515
"""Combine array-like of transfer functions into MIMO transfer function.
516516
517517
Parameters
@@ -527,6 +527,16 @@ def combine_tf(tf_array):
527527
TransferFunction
528528
Transfer matrix represented as a single MIMO TransferFunction object.
529529
530+
Other Parameters
531+
----------------
532+
inputs, outputs : str, or list of str, optional
533+
List of strings that name the individual signals. If not given,
534+
signal names will be of the form `s[i]` (where `s` is one of `u`,
535+
or `y`). See :class:`InputOutputSystem` for more information.
536+
name : string, optional
537+
System name (used for specifying signals). If unspecified, a generic
538+
name <sys[id]> is generated with a unique integer id.
539+
530540
Raises
531541
------
532542
ValueError
@@ -541,26 +551,22 @@ def combine_tf(tf_array):
541551
--------
542552
Combine two transfer functions
543553
544-
>>> s = control.TransferFunction.s
545-
>>> control.combine_tf([
546-
... [1 / (s + 1)],
547-
... [s / (s + 2)],
548-
... ])
549-
TransferFunction([[array([1])], [array([1, 0])]],
550-
[[array([1, 1])], [array([1, 2])]])
554+
>>> s = ct.tf('s')
555+
>>> ct.combine_tf(
556+
... [[1 / (s + 1)],
557+
... [s / (s + 2)]],
558+
... name='G'
559+
... )
560+
<TransferFunction G: ['u[0]'] -> ['y[0]', 'y[1]']>
551561
552562
Combine NumPy arrays with transfer functions
553563
554-
>>> control.combine_tf([
555-
... [np.eye(2), np.zeros((2, 1))],
556-
... [np.zeros((1, 2)), control.TransferFunction([1], [1, 0])],
557-
... ])
558-
TransferFunction([[array([1.]), array([0.]), array([0.])],
559-
[array([0.]), array([1.]), array([0.])],
560-
[array([0.]), array([0.]), array([1])]],
561-
[[array([1.]), array([1.]), array([1.])],
562-
[array([1.]), array([1.]), array([1.])],
563-
[array([1.]), array([1.]), array([1, 0])]])
564+
>>> ct.combine_tf(
565+
... [[np.eye(2), np.zeros((2, 1))],
566+
... [np.zeros((1, 2)), ct.tf([1], [1, 0])]],
567+
... name='G'
568+
... )
569+
<TransferFunction G: ['u[0]', 'u[1]', 'u[2]'] -> ['y[0]', 'y[1]', 'y[2]']>
564570
"""
565571
# Find common timebase or raise error
566572
dt_list = []
@@ -616,10 +622,14 @@ def combine_tf(tf_array):
616622
"Mismatched number transfer function inputs in row "
617623
f"{row_index} of denominator."
618624
)
619-
return tf.TransferFunction(num, den, dt=dt)
625+
return tf.TransferFunction(num, den, dt=dt, **kwargs)
626+
620627

621628
def split_tf(transfer_function):
622-
"""Split MIMO transfer function into NumPy array of SISO tranfer functions.
629+
"""Split MIMO transfer function into NumPy array of SISO transfer functions.
630+
631+
System and signal names for the array of SISO transfer functions are
632+
copied from the MIMO system.
623633
624634
Parameters
625635
----------
@@ -635,21 +645,18 @@ def split_tf(transfer_function):
635645
--------
636646
Split a MIMO transfer function
637647
638-
>>> G = control.TransferFunction(
639-
... [
640-
... [[87.8], [-86.4]],
641-
... [[108.2], [-109.6]],
642-
... ],
643-
... [
644-
... [[1, 1], [1, 1]],
645-
... [[1, 1], [1, 1]],
646-
... ],
648+
>>> G = ct.tf(
649+
... [ [[87.8], [-86.4]],
650+
... [[108.2], [-109.6]] ],
651+
... [ [[1, 1], [1, 1]],
652+
... [[1, 1], [1, 1]], ],
653+
... name='G'
647654
... )
648-
>>> control.split_tf(G)
649-
array([[TransferFunction(array([87.8]), array([1, 1])),
650-
TransferFunction(array([-86.4]), array([1, 1]))],
651-
[TransferFunction(array([108.2]), array([1, 1])),
652-
TransferFunction(array([-109.6]), array([1, 1]))]], dtype=object)
655+
>>> ct.split_tf(G)
656+
array([[<TransferFunction G: ['u[0]'] -> ['y[0]']>,
657+
<TransferFunction G: ['u[1]'] -> ['y[0]']>],
658+
[<TransferFunction G: ['u[0]'] -> ['y[1]']>,
659+
<TransferFunction G: ['u[1]'] -> ['y[1]']>]], dtype=object)
653660
"""
654661
tf_split_lst = []
655662
for i_out in range(transfer_function.noutputs):
@@ -660,6 +667,9 @@ def split_tf(transfer_function):
660667
transfer_function.num_array[i_out, i_in],
661668
transfer_function.den_array[i_out, i_in],
662669
dt=transfer_function.dt,
670+
inputs=transfer_function.input_labels[i_in],
671+
outputs=transfer_function.output_labels[i_out],
672+
name=transfer_function.name
663673
)
664674
)
665675
tf_split_lst.append(row)

control/lti.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -615,14 +615,14 @@ def bandwidth(sys, dbdrop=-3):
615615
-------
616616
>>> G = ct.tf([1], [1, 1])
617617
>>> ct.bandwidth(G)
618-
0.9976
618+
np.float64(0.9976283451102316)
619619
620620
>>> G1 = ct.tf(0.1, [1, 0.1])
621621
>>> wn2 = 1
622622
>>> zeta2 = 0.001
623623
>>> G2 = ct.tf(wn2**2, [1, 2*zeta2*wn2, wn2**2])
624624
>>> ct.bandwidth(G1*G2)
625-
0.1018
625+
np.float64(0.10184838823897456)
626626
627627
"""
628628
if not isinstance(sys, LTI):

control/tests/kwargs_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def test_kwarg_search(module, prefix):
9696
@pytest.mark.parametrize(
9797
"function, nsssys, ntfsys, moreargs, kwargs",
9898
[(control.append, 2, 0, (), {}),
99+
(control.combine_tf, 0, 0, ([[1, 0], [0, 1]], ), {}),
99100
(control.dlqe, 1, 0, ([[1]], [[1]]), {}),
100101
(control.dlqr, 1, 0, ([[1, 0], [0, 1]], [[1]]), {}),
101102
(control.drss, 0, 0, (2, 1, 1), {}),
@@ -245,6 +246,7 @@ def test_response_plot_kwargs(data_fcn, plot_fcn, mimo):
245246
'bode': test_response_plot_kwargs,
246247
'bode_plot': test_response_plot_kwargs,
247248
'LTI.bode_plot': test_response_plot_kwargs, # alias for bode_plot and tested via bode_plot
249+
'combine_tf': test_unrecognized_kwargs,
248250
'create_estimator_iosystem': stochsys_test.test_estimator_errors,
249251
'create_statefbk_iosystem': statefbk_test.TestStatefbk.test_statefbk_errors,
250252
'describing_function_plot': test_matplotlib_kwargs,

0 commit comments

Comments
 (0)