@@ -173,6 +173,9 @@ class TimeResponseData:
173
173
sysname : str, optional
174
174
Name of the system that created the data.
175
175
176
+ params : dict, optional
177
+ If system is a nonlinear I/O system, set parameter values.
178
+
176
179
plot_inputs : bool, optional
177
180
Whether or not to plot the inputs by default (can be overridden in
178
181
the plot() method)
@@ -227,7 +230,7 @@ def __init__(
227
230
output_labels = None , state_labels = None , input_labels = None ,
228
231
title = None , transpose = False , return_x = False , squeeze = None ,
229
232
multi_trace = False , trace_labels = None , trace_types = None ,
230
- plot_inputs = True , sysname = None
233
+ plot_inputs = True , sysname = None , params = None
231
234
):
232
235
"""Create an input/output time response object.
233
236
@@ -315,6 +318,7 @@ def __init__(
315
318
raise ValueError ("Time vector must be 1D array" )
316
319
self .title = title
317
320
self .sysname = sysname
321
+ self .params = params
318
322
319
323
#
320
324
# Output vector (and number of traces)
@@ -856,7 +860,7 @@ def shape_matches(s_legal, s_actual):
856
860
857
861
858
862
# Forced response of a linear system
859
- def forced_response (sys , T = None , U = 0. , X0 = 0. , transpose = False ,
863
+ def forced_response (sys , T = None , U = 0. , X0 = 0. , transpose = False , params = None ,
860
864
interpolate = False , return_x = None , squeeze = None ):
861
865
"""Compute the output of a linear system given the input.
862
866
@@ -889,6 +893,9 @@ def forced_response(sys, T=None, U=0., X0=0., transpose=False,
889
893
X0 : array_like or float, default=0.
890
894
Initial condition.
891
895
896
+ params : dict, optional
897
+ If system is a nonlinear I/O system, set parameter values.
898
+
892
899
transpose : bool, default=False
893
900
If True, transpose all input and output arrays (for backward
894
901
compatibility with MATLAB and :func:`scipy.signal.lsim`).
@@ -981,7 +988,7 @@ def forced_response(sys, T=None, U=0., X0=0., transpose=False,
981
988
warnings .warn (
982
989
"interpolation not supported for nonlinear I/O systems" )
983
990
return input_output_response (
984
- sys , T , U , X0 , transpose = transpose ,
991
+ sys , T , U , X0 , params = params , transpose = transpose ,
985
992
return_x = return_x , squeeze = squeeze )
986
993
else :
987
994
raise TypeError ('Parameter ``sys``: must be a ``StateSpace`` or'
@@ -1169,7 +1176,7 @@ def forced_response(sys, T=None, U=0., X0=0., transpose=False,
1169
1176
yout = np .transpose (yout )
1170
1177
1171
1178
return TimeResponseData (
1172
- tout , yout , xout , U , issiso = sys .issiso (),
1179
+ tout , yout , xout , U , params = params , issiso = sys .issiso (),
1173
1180
output_labels = sys .output_labels , input_labels = sys .input_labels ,
1174
1181
state_labels = sys .state_labels , sysname = sys .name , plot_inputs = True ,
1175
1182
title = "Forced response for " + sys .name , trace_types = ['forced' ],
@@ -1256,7 +1263,7 @@ def _process_time_response(
1256
1263
1257
1264
1258
1265
def step_response (sys , T = None , X0 = 0 , input = None , output = None , T_num = None ,
1259
- transpose = False , return_x = False , squeeze = None ):
1266
+ transpose = False , return_x = False , squeeze = None , params = None ):
1260
1267
# pylint: disable=W0622
1261
1268
"""Compute the step response for a linear system.
1262
1269
@@ -1298,6 +1305,9 @@ def step_response(sys, T=None, X0=0, input=None, output=None, T_num=None,
1298
1305
Only report the step response for the listed output. If not
1299
1306
specified, all outputs are reported.
1300
1307
1308
+ params : dict, optional
1309
+ If system is a nonlinear I/O system, set parameter values.
1310
+
1301
1311
T_num : int, optional
1302
1312
Number of time steps to use in simulation if T is not provided as an
1303
1313
array (autocomputed if not given); ignored if sys is discrete-time.
@@ -1403,7 +1413,7 @@ def step_response(sys, T=None, X0=0, input=None, output=None, T_num=None,
1403
1413
U = np .zeros ((sys .ninputs , T .size ))
1404
1414
U [i , :] = np .ones_like (T )
1405
1415
1406
- response = forced_response (sys , T , U , X0 , squeeze = True )
1416
+ response = forced_response (sys , T , U , X0 , squeeze = True , params = params )
1407
1417
inpidx = i if input is None else 0
1408
1418
yout [:, inpidx , :] = response .y if output is None \
1409
1419
else response .y [output ]
@@ -1424,11 +1434,11 @@ def step_response(sys, T=None, X0=0, input=None, output=None, T_num=None,
1424
1434
output_labels = output_labels , input_labels = input_labels ,
1425
1435
state_labels = sys .state_labels , title = "Step response for " + sys .name ,
1426
1436
transpose = transpose , return_x = return_x , squeeze = squeeze ,
1427
- sysname = sys .name , trace_labels = trace_labels ,
1437
+ sysname = sys .name , params = params , trace_labels = trace_labels ,
1428
1438
trace_types = trace_types , plot_inputs = False )
1429
1439
1430
1440
1431
- def step_info (sysdata , T = None , T_num = None , yfinal = None ,
1441
+ def step_info (sysdata , T = None , T_num = None , yfinal = None , params = None ,
1432
1442
SettlingTimeThreshold = 0.02 , RiseTimeLimits = (0.1 , 0.9 )):
1433
1443
"""
1434
1444
Step response characteristics (Rise time, Settling Time, Peak and others).
@@ -1451,6 +1461,8 @@ def step_info(sysdata, T=None, T_num=None, yfinal=None,
1451
1461
systems to simulate and the last value of the the response data is
1452
1462
used for a given time series of response data. Scalar for SISO,
1453
1463
(noutputs, ninputs) array_like for MIMO systems.
1464
+ params : dict, optional
1465
+ If system is a nonlinear I/O system, set parameter values.
1454
1466
SettlingTimeThreshold : float, optional
1455
1467
Defines the error to compute settling time (default = 0.02)
1456
1468
RiseTimeLimits : tuple (lower_threshold, upper_theshold)
@@ -1536,7 +1548,7 @@ def step_info(sysdata, T=None, T_num=None, yfinal=None,
1536
1548
from .nlsys import NonlinearIOSystem
1537
1549
1538
1550
if isinstance (sysdata , (StateSpace , TransferFunction , NonlinearIOSystem )):
1539
- T , Yout = step_response (sysdata , T , squeeze = False )
1551
+ T , Yout = step_response (sysdata , T , squeeze = False , params = params )
1540
1552
if yfinal :
1541
1553
InfValues = np .atleast_2d (yfinal )
1542
1554
else :
@@ -1651,7 +1663,7 @@ def step_info(sysdata, T=None, T_num=None, yfinal=None,
1651
1663
return ret [0 ][0 ] if retsiso else ret
1652
1664
1653
1665
1654
- def initial_response (sys , T = None , X0 = 0 , output = None , T_num = None ,
1666
+ def initial_response (sys , T = None , X0 = 0 , output = None , T_num = None , params = None ,
1655
1667
transpose = False , return_x = False , squeeze = None ):
1656
1668
# pylint: disable=W0622
1657
1669
"""Compute the initial condition response for a linear system.
@@ -1684,6 +1696,9 @@ def initial_response(sys, T=None, X0=0, output=None, T_num=None,
1684
1696
Number of time steps to use in simulation if T is not provided as an
1685
1697
array (autocomputed if not given); ignored if sys is discrete-time.
1686
1698
1699
+ params : dict, optional
1700
+ If system is a nonlinear I/O system, set parameter values.
1701
+
1687
1702
transpose : bool, optional
1688
1703
If True, transpose all input and output arrays (for backward
1689
1704
compatibility with MATLAB and :func:`scipy.signal.lsim`). Default
@@ -1748,7 +1763,7 @@ def initial_response(sys, T=None, X0=0, output=None, T_num=None,
1748
1763
raise ValueError ("invalid value of T for this type of system" )
1749
1764
1750
1765
# Compute the forced response
1751
- response = forced_response (sys , T , 0 , X0 )
1766
+ response = forced_response (sys , T , 0 , X0 , params = params )
1752
1767
1753
1768
# Figure out if the system is SISO or not
1754
1769
issiso = sys .issiso () or output is not None
@@ -1760,7 +1775,7 @@ def initial_response(sys, T=None, X0=0, output=None, T_num=None,
1760
1775
1761
1776
# Store the response without an input
1762
1777
return TimeResponseData (
1763
- response .t , yout , response .x , None , issiso = issiso ,
1778
+ response .t , yout , response .x , None , params = params , issiso = issiso ,
1764
1779
output_labels = output_labels , input_labels = None ,
1765
1780
state_labels = sys .state_labels , sysname = sys .name ,
1766
1781
title = "Initial response for " + sys .name , trace_types = ['initial' ],
@@ -1863,6 +1878,10 @@ def impulse_response(sys, T=None, input=None, output=None, T_num=None,
1863
1878
from .statesp import _convert_to_statespace
1864
1879
from .lti import LTI
1865
1880
1881
+ # Make sure we have an LTI system
1882
+ if not isinstance (sys , LTI ):
1883
+ raise ValueError ("system must be LTI system for impulse response" )
1884
+
1866
1885
# Create the time and input vectors
1867
1886
if T is None or np .asarray (T ).size == 1 :
1868
1887
T = _default_time_vector (sys , N = T_num , tfinal = T , is_step = False )
0 commit comments