Skip to content

Commit 98fdb35

Browse files
committed
clean up/simplify docstring examples
1 parent c4c275f commit 98fdb35

20 files changed

+85
-128
lines changed

control/bdalg.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,13 @@ def negate(sys):
190190
191191
Examples
192192
--------
193-
>>> G = ct.tf([2],[1, 1])
194-
>>> G.dcgain() > 0
195-
True
193+
>>> G = ct.tf([2], [1, 1])
194+
>>> G.dcgain()
195+
2.0
196196
197197
>>> Gn = ct.negate(G) # Same as sys2 = -sys1.
198-
>>> Gn.dcgain() < 0
199-
True
198+
>>> Gn.dcgain()
199+
-2.0
200200
201201
"""
202202
return -sys

control/canonical.py

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,20 @@ def canonical_form(xsys, form='reachable'):
3939
4040
Examples
4141
--------
42-
>>> G = ct.tf([1],[1, 3, 2])
43-
>>> Gs = ct.tf2ss(G)
42+
>>> Gs = ct.tf2ss([1], [1, 3, 2])
4443
>>> Gc, T = ct.canonical_form(Gs) # default reachable
45-
>>> Gc.B # doctest: +SKIP
46-
matrix([[1.],
47-
[0.]])
44+
>>> Gc.B
45+
array([[1.],
46+
[0.]])
4847
4948
>>> Gc, T = ct.canonical_form(Gs, 'observable')
50-
>>> Gc.C # doctest: +SKIP
51-
matrix([[1., 0.]])
49+
>>> Gc.C
50+
array([[1., 0.]])
5251
5352
>>> Gc, T = ct.canonical_form(Gs, 'modal')
54-
>>> Gc.A # doctest: +SKIP
55-
matrix([[-2., 0.],
56-
[ 0., -1.]])
53+
>>> Gc.A
54+
array([[-2., 0.],
55+
[ 0., -1.]])
5756
5857
"""
5958

@@ -87,8 +86,7 @@ def reachable_form(xsys):
8786
8887
Examples
8988
--------
90-
>>> G = ct.tf([1],[1, 3, 2])
91-
>>> Gs = ct.tf2ss(G)
89+
>>> Gs = ct.tf2ss([1], [1, 3, 2])
9290
>>> Gc, T = ct.reachable_form(Gs) # default reachable
9391
>>> Gc.B # doctest: +SKIP
9492
matrix([[1.],
@@ -151,8 +149,7 @@ def observable_form(xsys):
151149
152150
Examples
153151
--------
154-
>>> G = ct.tf([1],[1, 3, 2])
155-
>>> Gs = ct.tf2ss(G)
152+
>>> Gs = ct.tf2ss([1], [1, 3, 2])
156153
>>> Gc, T = ct.observable_form(Gs)
157154
>>> Gc.C # doctest: +SKIP
158155
matrix([[1., 0.]])
@@ -218,8 +215,7 @@ def similarity_transform(xsys, T, timescale=1, inverse=False):
218215
219216
Examples
220217
--------
221-
>>> G = ct.tf([1],[1, 3, 2])
222-
>>> Gs = ct.tf2ss(G)
218+
>>> Gs = ct.tf2ss([1], [1, 3, 2])
223219
>>> Gs.A # doctest: +SKIP
224220
matrix([[-3., -2.],
225221
[ 1., 0.]])
@@ -426,8 +422,7 @@ def bdschur(a, condmax=None, sort=None):
426422
427423
Examples
428424
--------
429-
>>> G = ct.tf([1],[1, 3, 2])
430-
>>> Gs = ct.tf2ss(G)
425+
>>> Gs = ct.tf2ss([1], [1, 3, 2])
431426
>>> amodal, tmodal, blksizes = ct.bdschur(Gs.A)
432427
>>> amodal #doctest: +SKIP
433428
array([[-2., 0.],
@@ -502,8 +497,7 @@ def modal_form(xsys, condmax=None, sort=False):
502497
503498
Examples
504499
--------
505-
>>> G = ct.tf([1],[1, 3, 2])
506-
>>> Gs = ct.tf2ss((G))
500+
>>> Gs = ct.tf2ss([1], [1, 3, 2])
507501
>>> Gc, T = ct.modal_form(Gs) # default reachable
508502
>>> Gc.A # doctest: +SKIP
509503
matrix([[-2., 0.],

control/config.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,8 @@ def set_defaults(module, **keywords):
7474
>>> ct.set_defaults('freqplot', number_of_samples=100)
7575
>>> ct.defaults['freqplot.number_of_samples']
7676
100
77-
7877
>>> # do some customized freqplotting
7978
>>> ct.reset_defaults()
80-
>>> ct.defaults['freqplot.number_of_samples']
81-
1000
8279
8380
"""
8481
if not isinstance(module, str):

control/ctrlutil.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ def issys(obj):
9090
9191
Examples
9292
--------
93-
>>> G = ct.tf([1],[1, 1])
93+
>>> G = ct.tf([1], [1, 1])
9494
>>> ct.issys(G)
9595
True
9696
97-
>>> K = ct.InputOutputSystem() # Not necessarily LTI!
97+
>>> K = np.array([[1, 1]])
9898
>>> ct.issys(K)
9999
False
100100

control/delay.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ def pade(T, n=1, numdeg=None):
7878
Examples
7979
--------
8080
>>> delay = 1
81-
>>> num, den = ct.pade(delay, 5)
82-
>>> len(num), len(den)
83-
(6, 6)
81+
>>> num, den = ct.pade(delay, 3)
82+
>>> num, den
83+
([-1.0, 12.0, -60.0, 120.0], [1.0, 12.0, 60.0, 120.0])
8484
85-
>>> num, den = ct.pade(delay, 5, -2)
86-
>>> len(num), len(den)
87-
(4, 6)
85+
>>> num, den = ct.pade(delay, 3, -2)
86+
>>> num, den
87+
([-6.0, 24.0], [1.0, 6.0, 18.0, 24.0])
8888
8989
"""
9090
if numdeg is None:

control/descfcn.py

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,8 @@ def describing_function_plot(
249249
>>> H_simple = ct.tf([8], [1, 2, 2, 1])
250250
>>> F_saturation = ct.saturation_nonlinearity(1)
251251
>>> amp = np.linspace(1, 4, 10)
252-
>>> points = ct.describing_function_plot(H_simple, F_saturation, amp)
253-
>>> len(points)
254-
1
252+
>>> ct.describing_function_plot(H_simple, F_saturation, amp)
253+
[(3.343844998258643, 1.4142293090899216)]
255254
256255
"""
257256
# Decide whether to turn on warnings or not
@@ -366,12 +365,11 @@ class saturation_nonlinearity(DescribingFunctionNonlinearity):
366365
Examples
367366
--------
368367
>>> nl = ct.saturation_nonlinearity(5)
369-
>>> f = lambda x: round(nl(x))
370-
>>> f(1)
368+
>>> nl(1)
371369
1
372-
>>> f(10)
370+
>>> nl(10)
373371
5
374-
>>> f(-10)
372+
>>> nl(-10)
375373
-5
376374
377375
"""
@@ -430,16 +428,15 @@ class relay_hysteresis_nonlinearity(DescribingFunctionNonlinearity):
430428
Examples
431429
--------
432430
>>> nl = ct.relay_hysteresis_nonlinearity(1, 2)
433-
>>> f = lambda x: round(nl(x))
434-
>>> f(0)
431+
>>> nl(0)
435432
-1
436-
>>> f(1) # not enough for switching on
433+
>>> nl(1) # not enough for switching on
437434
-1
438-
>>> f(5)
435+
>>> nl(5)
439436
1
440-
>>> f(-1) # not enough for switching off
437+
>>> nl(-1) # not enough for switching off
441438
1
442-
>>> f(-5)
439+
>>> nl(-5)
443440
-1
444441
445442
"""
@@ -500,19 +497,18 @@ class friction_backlash_nonlinearity(DescribingFunctionNonlinearity):
500497
Examples
501498
--------
502499
>>> nl = ct.friction_backlash_nonlinearity(2) # backlash of +/- 1
503-
>>> f = lambda x: round(nl(x))
504-
>>> f(0)
505-
0
506-
>>> f(1) # not enough to overcome backlash
500+
>>> nl(0)
507501
0
508-
>>> f(2)
509-
1
510-
>>> f(1)
511-
1
512-
>>> f(0) # not enough to overcome backlash
513-
1
514-
>>> f(-1)
502+
>>> nl(1) # not enough to overcome backlash
515503
0
504+
>>> nl(2)
505+
1.0
506+
>>> nl(1)
507+
1.0
508+
>>> nl(0) # not enough to overcome backlash
509+
1.0
510+
>>> nl(-1)
511+
0.0
516512
517513
"""
518514

control/exception.py

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,7 @@ class ControlNotImplemented(NotImplementedError):
6363
# Utility function to see if slycot is installed
6464
slycot_installed = None
6565
def slycot_check():
66-
"""Return True if slycot is installed, otherwise False.
67-
68-
Examples
69-
--------
70-
>>> ct.slycot_check()
71-
True
72-
73-
"""
66+
"""Return True if slycot is installed, otherwise False."""
7467
global slycot_installed
7568
if slycot_installed is None:
7669
try:
@@ -84,15 +77,7 @@ def slycot_check():
8477
# Utility function to see if pandas is installed
8578
pandas_installed = None
8679
def pandas_check():
87-
"""Return True if pandas is installed, otherwise False.
88-
89-
Examples
90-
--------
91-
>>> ct.pandas_check()
92-
True
93-
94-
"""
95-
80+
"""Return True if pandas is installed, otherwise False."""
9681
global pandas_installed
9782
if pandas_installed is None:
9883
try:
@@ -105,14 +90,7 @@ def pandas_check():
10590
# Utility function to see if cvxopt is installed
10691
cvxopt_installed = None
10792
def cvxopt_check():
108-
"""Return True if cvxopt is installed, otherwise False.
109-
110-
Examples
111-
--------
112-
>>> ct.cvxopt_check()
113-
True
114-
115-
"""
93+
"""Return True if cvxopt is installed, otherwise False."""
11694
global cvxopt_installed
11795
if cvxopt_installed is None:
11896
try:

control/frdata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ def _convert_to_FRD(sys, omega, inputs=1, outputs=1):
672672
a frequency response data at the specified omega. If sys is a
673673
scalar, then the number of inputs and outputs can be specified
674674
manually, as in:
675-
+
675+
676676
>>> import numpy as np
677677
>>> from control.frdata import _convert_to_FRD
678678

control/freqplot.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def bode_plot(syslist, omega=None,
174174
175175
Examples
176176
--------
177-
>>> G = ct.ss("1. -2; 3. -4", "5.; 7", "6. 8", "9.")
177+
>>> G = ct.ss([[-1, -2], [3, -4]], [[5], [7]], [[6, 8]], [[9]])
178178
>>> Gmag, Gphase, Gomega = ct.bode_plot(G)
179179
180180
"""
@@ -692,7 +692,7 @@ def nyquist_plot(
692692
693693
Examples
694694
--------
695-
>>> G = ct.zpk([],[-1,-2,-3], gain=100)
695+
>>> G = ct.zpk([], [-1, -2, -3], gain=100)
696696
>>> ct.nyquist_plot(G)
697697
2
698698
@@ -1262,8 +1262,8 @@ def gangof4_plot(P, C, omega=None, **kwargs):
12621262
12631263
Examples
12641264
--------
1265-
>>> P = ct.tf([1],[1, 1])
1266-
>>> C = ct.tf([2],[1])
1265+
>>> P = ct.tf([1], [1, 1])
1266+
>>> C = ct.tf([2], [1])
12671267
>>> ct.gangof4_plot(P, C)
12681268
12691269
"""
@@ -1411,7 +1411,8 @@ def singular_values_plot(syslist, omega=None,
14111411
--------
14121412
>>> omegas = np.logspace(-4, 1, 1000)
14131413
>>> den = [75, 1]
1414-
>>> G = ct.tf([[[87.8], [-86.4]], [[108.2], [-109.6]]], [[den, den], [den, den]])
1414+
>>> G = ct.tf([[[87.8], [-86.4]], [[108.2], [-109.6]]],
1415+
... [[den, den], [den, den]])
14151416
>>> sigmas, omegas = ct.singular_values_plot(G, omega=omegas, plot=False)
14161417
14171418
>>> sigmas, omegas = ct.singular_values_plot(G, 0.0, plot=False)
@@ -1630,7 +1631,7 @@ def _default_frequency_range(syslist, Hz=None, number_of_samples=None,
16301631
16311632
Examples
16321633
--------
1633-
>>> G = ct.ss("1. -2; 3. -4", "5.; 7", "6. 8", "9.")
1634+
>>> G = ct.ss([[-1, -2], [3, -4]], [[5], [7]], [[6, 8]], [[9]])
16341635
>>> omega = ct._default_frequency_range(G)
16351636
>>> omega.min(), omega.max()
16361637
(0.1, 100.0)

control/iosys.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2373,7 +2373,7 @@ def ss(*args, **kwargs):
23732373
--------
23742374
Create a Linear I/O system object from matrices.
23752375
2376-
>>> G = ct.ss([[1, -2], [3, -4]], [[5], [7]], [[6, 8]], [[9]])
2376+
>>> G = ct.ss([[-1, -2], [3, -4]], [[5], [7]], [[6, 8]], [[9]])
23772377
23782378
Convert a TransferFunction to a StateSpace object.
23792379
@@ -2778,12 +2778,8 @@ def interconnect(
27782778
27792779
Examples
27802780
--------
2781-
>>> P = ct.LinearIOSystem(
2782-
... ct.rss(2, 2, 2, strictly_proper=True),
2783-
... name='P')
2784-
>>> C = ct.LinearIOSystem(
2785-
... ct.rss(2, 2, 2),
2786-
... name='C')
2781+
>>> P = ct.rss(2, 2, 2, strictly_proper=True, name='P')
2782+
>>> C = ct.rss(2, 2, 2, name='C')
27872783
>>> T = ct.interconnect(
27882784
... [P, C],
27892785
... connections = [
@@ -3002,10 +2998,10 @@ def summing_junction(
30022998
30032999
Examples
30043000
--------
3005-
>>> P = ct.tf2io(ct.tf(1, [1, 0]), inputs='u', outputs='y')
3006-
>>> C = ct.tf2io(ct.tf(10, [1, 1]), inputs='e', outputs='u')
3001+
>>> P = ct.tf2io(1, [1, 0], inputs='u', outputs='y')
3002+
>>> C = ct.tf2io(10, [1, 1], inputs='e', outputs='u')
30073003
>>> sumblk = ct.summing_junction(inputs=['r', '-y'], output='e')
3008-
>>> T = ct.interconnect((P, C, sumblk), inputs='r', outputs='y')
3004+
>>> T = ct.interconnect([P, C, sumblk], inputs='r', outputs='y')
30093005
>>> T.ninputs, T.noutputs, T.nstates
30103006
(1, 1, 2)
30113007

control/lti.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,8 @@ def damp(sys, doprint=True):
326326
327327
Examples
328328
--------
329-
>>> G = ct.tf([1],[1, 4])
330-
>>> wn, damping, poles = ct.damp(G) # doctest: +SKIP
329+
>>> G = ct.tf([1], [1, 4])
330+
>>> wn, damping, poles = ct.damp(G)
331331
_____Eigenvalue______ Damping___ Frequency_
332332
-4 1 4
333333
@@ -393,7 +393,7 @@ def evalfr(sys, x, squeeze=None):
393393
394394
Examples
395395
--------
396-
>>> G = ct.ss("1. -2; 3. -4", "5.; 7", "6. 8", "9.")
396+
>>> G = ct.ss([[-1, -2], [3, -4]], [[5], [7]], [[6, 8]], [[9]])
397397
>>> fresp = ct.evalfr(G, 1j) # evaluate at s = 1j
398398
399399
.. todo:: Add example with MIMO system
@@ -454,7 +454,7 @@ def frequency_response(sys, omega, squeeze=None):
454454
455455
Examples
456456
--------
457-
>>> G = ct.ss("1. -2; 3. -4", "5.; 7", "6. 8", "9.")
457+
>>> G = ct.ss([[-1, -2], [3, -4]], [[5], [7]], [[6, 8]], [[9]])
458458
>>> mag, phase, omega = ct.freqresp(G, [0.1, 1., 10.])
459459
460460
.. todo::

0 commit comments

Comments
 (0)