control.input_output_response
- control.input_output_response(sys, timepts=None, inputs=0.0, initial_state=0.0, params=None, ignore_errors=False, transpose=False, return_states=False, squeeze=None, solve_ivp_kwargs=None, evaluation_times='T', **kwargs)[source]
Compute the output response of a system to a given input.
Simulate a dynamical system with a given input and return its output and state values.
- Parameters:
- sys
NonlinearIOSystemor list ofNonlinearIOSystem I/O system(s) for which input/output response is simulated.
- timepts (or T)array_like
Time steps at which the input is defined; values must be evenly spaced.
- inputs (or U)array_like, list, or number, optional
Input array giving input at each time in
timepts(default = 0). If a list is specified, each element in the list will be treated as a portion of the input and broadcast (if necessary) to match the time vector.- initial_state (or X0)array_like, list, or number, optional
Initial condition (default = 0). If a list is given, each element in the list will be flattened and stacked into the initial condition. If a smaller number of elements are given that the number of states in the system, the initial condition will be padded with zeros.
- evaluation_times (or t_eval)array-list, optional
List of times at which the time response should be computed. Defaults to
timepts.- return_states (or return_x)bool, optional
If True, return the state vector when assigning to a tuple. See
forced_responsefor more details. If True, return the values of the state at each time Default is False.- paramsdict, optional
Parameter values for the system. Passed to the evaluation functions for the system as default values, overriding internal defaults.
- squeezebool, optional
If True and if the system has a single output, return the system output as a 1D array rather than a 2D array. If False, return the system output as a 2D array even if the system is SISO. Default value set by
config.defaults['control.squeeze_time_response'].
- sys
- Returns:
- response
TimeResponseData Time response data object representing the input/output response. When accessed as a tuple, returns
(time, outputs)or(time, outputs, statesifreturn_xis True. If the input/output system signals are named, these names will be used as labels for the time response. Ifsysis a list of systems, returns aTimeResponseListobject. Results can be plotted using theplotmethod. SeeTimeResponseDatafor more detailed information.- response.timearray
Time values of the output.
- response.outputsarray
Response of the system. If the system is SISO and
squeezeis not True, the array is 1D (indexed by time). If the system is not SISO orsqueezeis False, the array is 2D (indexed by output and time).- response.statesarray
Time evolution of the state vector, represented as a 2D array indexed by state and time.
- response.inputsarray
Input(s) to the system, indexed by input and time.
- response.paramsdict
Parameters values used for the simulation.
- response
- Other Parameters:
- ignore_errorsbool, optional
If False (default), errors during computation of the trajectory will raise a
RuntimeErrorexception. If True, do not raise an exception and instead setresponse.successto False and place an error message inresponse.message.- solve_ivp_methodstr, optional
Set the method used by
scipy.integrate.solve_ivp. Defaults to ‘RK45’.- solve_ivp_kwargsdict, optional
Pass additional keywords to
scipy.integrate.solve_ivp.- transposebool, default=False
If True, transpose all input and output arrays (for backward compatibility with MATLAB and
scipy.signal.lsim).
- Raises:
- TypeError
If the system is not an input/output system.
- ValueError
If time step does not match sampling time (for discrete-time systems).
Notes
If a smaller number of initial conditions are given than the number of states in the system, the initial conditions will be padded with zeros. This is often useful for interconnected control systems where the process dynamics are the first system and all other components start with zero initial condition since this can be specified as [xsys_0, 0]. A warning is issued if the initial conditions are padded and and the final listed initial state is not zero.
If discontinuous inputs are given, the underlying SciPy numerical integration algorithms can sometimes produce erroneous results due to the default tolerances that are used. The
solve_ivp_methodandsolve_ivp_keywordsparameters can be used to tune the ODE solver and produce better results. In particular, using ‘LSODA’ as thesolve_ivp_method, setting thertolparameter to a smaller value (e.g. usingsolve_ivp_kwargs={'rtol': 1e-4}), or setting the maximum step size to a smaller value (e.g.solve_ivp_kwargs= {'max_step': 0.01}) can provide more accurate results.