Skip to content

Commit a38edfc

Browse files
committed
corrected comments on time responses, with the "input" parameter to be
ignored on initial response calculation; initial response does not depend on input!
1 parent 1d4dd64 commit a38edfc

4 files changed

Lines changed: 52 additions & 43 deletions

File tree

src/matlab.py

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,15 +1103,18 @@ def rlocus(sys, klist = None, **keywords):
11031103
"""Root locus plot
11041104
11051105
The root-locus plot has a callback function that prints pole location,
1106-
gain and damping to the Python consol on mouseclicks on the root-locus
1107-
graph.
1106+
gain and damping to the Python console on mouseclicks on the root-locus
1107+
graph.
11081108
11091109
Parameters
11101110
----------
11111111
sys: StateSpace or TransferFunction
11121112
Linear system
11131113
klist:
11141114
optional list of gains
1115+
1116+
Keyword parameters
1117+
------------------
11151118
xlim : control of x-axis range, normally with tuple, for
11161119
other options, see matplotlib.axes
11171120
ylim : control of y-axis range
@@ -1165,7 +1168,7 @@ def margin(*args):
11651168
margin: no magnitude crossings found
11661169
11671170
.. todo::
1168-
better ecample system!
1171+
better example system!
11691172
11701173
#>>> gm, pm, wg, wp = margin(mag, phase, w)
11711174
"""
@@ -1178,7 +1181,7 @@ def margin(*args):
11781181
raise ValueError("Margin needs 1 or 3 arguments; received %i."
11791182
% len(args))
11801183

1181-
return margin[0], margin[1], margin[4], margin[3]
1184+
return margin[0], margin[1], margin[3], margin[4]
11821185

11831186
def dcgain(*args):
11841187
'''
@@ -1279,10 +1282,11 @@ def step(sys, T=None, X0=0., input=0, output=None, **keywords):
12791282
'''
12801283
Step response of a linear system
12811284
1282-
If the system has multiple inputs or outputs (MIMO), one input and one
1283-
output have to be selected for the simulation. The parameters `input`
1284-
and `output` do this. All other inputs are set to 0, all other outputs
1285-
are ignored.
1285+
If the system has multiple inputs or outputs (MIMO), one input has
1286+
to be selected for the simulation. Optionally, one output may be
1287+
selected. If no selection is made for the output, all outputs are
1288+
given. The parameters `input` and `output` do this. All other
1289+
inputs are set to 0, all other outputs are ignored.
12861290
12871291
Parameters
12881292
----------
@@ -1301,7 +1305,7 @@ def step(sys, T=None, X0=0., input=0, output=None, **keywords):
13011305
Index of the input that will be used in this simulation.
13021306
13031307
output: int
1304-
Index of the output that will be used in this simulation.
1308+
If given, index of the output that is returned by this simulation.
13051309
13061310
**keywords:
13071311
Additional keyword arguments control the solution algorithm for the
@@ -1326,19 +1330,21 @@ def step(sys, T=None, X0=0., input=0, output=None, **keywords):
13261330
Examples
13271331
--------
13281332
>>> yout, T = step(sys, T, X0)
1333+
13291334
'''
13301335
T, yout = timeresp.step_response(sys, T, X0, input, output,
1331-
transpose = True, **keywords)
1336+
transpose=True, **keywords)
13321337
return yout, T
13331338

1334-
def impulse(sys, T=None, input=0, output=0, **keywords):
1339+
def impulse(sys, T=None, input=0, output=None, **keywords):
13351340
'''
13361341
Impulse response of a linear system
13371342
1338-
If the system has multiple inputs or outputs (MIMO), one input and
1339-
one output must be selected for the simulation. The parameters
1340-
`input` and `output` do this. All other inputs are set to 0, all
1341-
other outputs are ignored.
1343+
If the system has multiple inputs or outputs (MIMO), one input has
1344+
to be selected for the simulation. Optionally, one output may be
1345+
selected. If no selection is made for the output, all outputs are
1346+
given. The parameters `input` and `output` do this. All other
1347+
inputs are set to 0, all other outputs are ignored.
13421348
13431349
Parameters
13441350
----------
@@ -1381,14 +1387,13 @@ def impulse(sys, T=None, input=0, output=0, **keywords):
13811387
transpose = True, **keywords)
13821388
return yout, T
13831389

1384-
def initial(sys, T=None, X0=0., input=0, output=0, **keywords):
1390+
def initial(sys, T=None, X0=0., input=None, output=None, **keywords):
13851391
'''
13861392
Initial condition response of a linear system
13871393
1388-
If the system has multiple inputs or outputs (MIMO), one input and one
1389-
output have to be selected for the simulation. The parameters `input`
1390-
and `output` do this. All other inputs are set to 0, all other outputs
1391-
are ignored.
1394+
If the system has multiple outputs (?IMO), optionally, one output
1395+
may be selected. If no selection is made for the output, all
1396+
outputs are given.
13921397
13931398
Parameters
13941399
----------
@@ -1404,10 +1409,11 @@ def initial(sys, T=None, X0=0., input=0, output=0, **keywords):
14041409
Numbers are converted to constant arrays with the correct shape.
14051410
14061411
input: int
1407-
Index of the input that will be used in this simulation.
1412+
This input is ignored, but present for compatibility with step
1413+
and impulse.
14081414
14091415
output: int
1410-
Index of the output that will be used in this simulation.
1416+
If given, index of the output that is returned by this simulation.
14111417
14121418
**keywords:
14131419
Additional keyword arguments control the solution algorithm for the
@@ -1432,9 +1438,10 @@ def initial(sys, T=None, X0=0., input=0, output=0, **keywords):
14321438
Examples
14331439
--------
14341440
>>> T, yout = initial(sys, T, X0)
1441+
14351442
'''
1436-
T, yout = timeresp.initial_response(sys, T, X0, input, output,
1437-
transpose = True, **keywords)
1443+
T, yout = timeresp.initial_response(sys, T, X0, output=output,
1444+
transpose=True, **keywords)
14381445
return yout, T
14391446

14401447
def lsim(sys, U=0., T=None, X0=0., **keywords):

src/timeresp.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,8 @@ def f_dot(x, t):
389389
def step_response(sys, T=None, X0=0., input=0, output=None,
390390
transpose = False, **keywords):
391391
#pylint: disable=W0622
392-
"""Step response of a linear system
392+
"""
393+
Step response of a linear system
393394
394395
If the system has multiple inputs or outputs (MIMO), one input has
395396
to be selected for the simulation. Optionally, one output may be
@@ -468,15 +469,14 @@ def step_response(sys, T=None, X0=0., input=0, output=None,
468469
return T, yout
469470

470471

471-
def initial_response(sys, T=None, X0=0., input=0, output=None, transpose=False,
472-
**keywords):
472+
def initial_response(sys, T=None, X0=0., input=None, output=None,
473+
transpose=False, **keywords):
473474
#pylint: disable=W0622
474475
"""Initial condition response of a linear system
475476
476-
If the system has multiple inputs or outputs (MIMO), one input and one
477-
output have to be selected for the simulation. The parameters `input`
478-
and `output` do this. All other inputs are set to 0, all other outputs
479-
are ignored.
477+
If the system has multiple outputs (?IMO), optionally, one output
478+
may be selected. If no selection is made for the output, all
479+
outputs are given.
480480
481481
For information on the **shape** of parameters `T`, `X0` and
482482
return values `T`, `yout` see: :ref:`time-series-convention`
@@ -495,7 +495,8 @@ def initial_response(sys, T=None, X0=0., input=0, output=None, transpose=False,
495495
Numbers are converted to constant arrays with the correct shape.
496496
497497
input: int
498-
Index of the input that will be used in this simulation.
498+
Ignored, has no meaning in initial condition calculation. Parameter
499+
ensures compatibility with step_response and impulse_response
499500
500501
output: int
501502
Index of the output that will be used in this simulation. Set to None
@@ -531,9 +532,9 @@ def initial_response(sys, T=None, X0=0., input=0, output=None, transpose=False,
531532
"""
532533
sys = _convertToStateSpace(sys)
533534
if output == None:
534-
sys = _mimo2simo(sys, input, warn_conversion=False)
535+
sys = _mimo2simo(sys, 0, warn_conversion=False)
535536
else:
536-
sys = _mimo2siso(sys, input, output, warn_conversion=False)
537+
sys = _mimo2siso(sys, 0, output, warn_conversion=False)
537538

538539
# Create time and input vectors; checking is done in forced_response(...)
539540
# The initial vector X0 is created in forced_response(...) if necessary
@@ -549,12 +550,13 @@ def initial_response(sys, T=None, X0=0., input=0, output=None, transpose=False,
549550
def impulse_response(sys, T=None, X0=0., input=0, output=None,
550551
transpose=False, **keywords):
551552
#pylint: disable=W0622
552-
"""Impulse response of a linear system
553+
"""
554+
Impulse response of a linear system
553555
554-
If the system has multiple inputs or outputs (MIMO), one input and one
555-
output have to be selected for the simulation. The parameters `input`
556-
and `output` do this. All other inputs are set to 0, all other outputs
557-
are ignored.
556+
If the system has multiple inputs or outputs (MIMO), one input has
557+
to be selected for the simulation. Optionally, one output may be
558+
selected. The parameters `input` and `output` do this. All other
559+
inputs are set to 0, all other outputs are ignored.
558560
559561
For information on the **shape** of parameters `T`, `X0` and
560562
return values `T`, `yout` see: :ref:`time-series-convention`

tests/matlab_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ def testInitial(self):
190190
#Test MIMO system, which contains ``siso_ss1`` twice
191191
sys = self.mimo_ss1
192192
x0 = np.matrix(".5; 1.; .5; 1.")
193-
y_00, _t = initial(sys, T=t, X0=x0, input=0, output=0)
194-
y_11, _t = initial(sys, T=t, X0=x0, input=1, output=1)
193+
y_00, _t = initial(sys, T=t, X0=x0, output=0)
194+
y_11, _t = initial(sys, T=t, X0=x0, output=1)
195195
np.testing.assert_array_almost_equal(y_00, youttrue, decimal=4)
196196
np.testing.assert_array_almost_equal(y_11, youttrue, decimal=4)
197197

tests/timeresp_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ def test_initial_response(self):
109109
#Test MIMO system, which contains ``siso_ss1`` twice
110110
sys = self.mimo_ss1
111111
x0 = np.matrix(".5; 1.; .5; 1.")
112-
_t, y_00 = initial_response(sys, T=t, X0=x0, input=0, output=0)
113-
_t, y_11 = initial_response(sys, T=t, X0=x0, input=1, output=1)
112+
_t, y_00 = initial_response(sys, T=t, X0=x0, output=0)
113+
_t, y_11 = initial_response(sys, T=t, X0=x0, output=1)
114114
np.testing.assert_array_almost_equal(y_00, youttrue, decimal=4)
115115
np.testing.assert_array_almost_equal(y_11, youttrue, decimal=4)
116116

0 commit comments

Comments
 (0)