Skip to content

Commit a660fbd

Browse files
author
KronosKoderS
committed
Added return_x to step_response
Added the ability to return the individual x variable responses from the step_response function. Also updated matlab version to match matlab returns.
1 parent 8ada9b2 commit a660fbd

2 files changed

Lines changed: 22 additions & 5 deletions

File tree

control/matlab/timeresp.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
__all__ = ['step', 'impulse', 'initial', 'lsim']
88

9-
def step(sys, T=None, X0=0., input=0, output=None):
9+
def step(sys, T=None, X0=0., input=0, output=None, return_x=False):
1010
'''
1111
Step response of a linear system
1212
@@ -40,9 +40,14 @@ def step(sys, T=None, X0=0., input=0, output=None):
4040
yout: array
4141
Response of the system
4242
43+
xout: array (if selected)
44+
Individual response of each x variable
45+
4346
T: array
4447
Time values of the output
4548
49+
50+
4651
See Also
4752
--------
4853
lsim, initial, impulse
@@ -52,8 +57,14 @@ def step(sys, T=None, X0=0., input=0, output=None):
5257
>>> yout, T = step(sys, T, X0)
5358
'''
5459
from ..timeresp import step_response
55-
T, yout = step_response(sys, T, X0, input, output,
56-
transpose = True)
60+
61+
62+
T, yout, xout = step_response(sys, T, X0, input, output,
63+
transpose = True, return_x=return_x)
64+
65+
if return_x:
66+
return yout, xout, T
67+
5768
return yout, T
5869

5970
def impulse(sys, T=None, input=0, output=None):

control/timeresp.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ def _get_ss_simo(sys, input=None, output=None):
417417
return _mimo2siso(sys_ss, input, output, warn_conversion=warn)
418418

419419
def step_response(sys, T=None, X0=0., input=None, output=None,
420-
transpose=False):
420+
transpose=False, return_x=False):
421421
# pylint: disable=W0622
422422
"""Step response of a linear system
423423
@@ -461,6 +461,9 @@ def step_response(sys, T=None, X0=0., input=None, output=None,
461461
yout: array
462462
Response of the system
463463
464+
xout: array
465+
Individual response of each x variable
466+
464467
See Also
465468
--------
466469
forced_response, initial_response, impulse_response
@@ -480,9 +483,12 @@ def step_response(sys, T=None, X0=0., input=None, output=None,
480483

481484
U = np.ones_like(T)
482485

483-
T, yout, _xout = forced_response(sys, T, U, X0,
486+
T, yout, xout = forced_response(sys, T, U, X0,
484487
transpose=transpose)
485488

489+
if return_x:
490+
return T, yout, xout
491+
486492
return T, yout
487493

488494

0 commit comments

Comments
 (0)