control.forced_response

control.forced_response(sys, T=None, U=0.0, X0=0.0, transpose=False, interpolate=False, return_x=None, squeeze=None)

Simulate the output of a linear system.

As a convenience for parameters U, X0: Numbers (scalars) are converted to constant arrays with the correct shape. The correct shape is inferred from arguments sys and T.

For information on the shape of parameters U, T, X0 and return values T, yout, xout, see Time series data.

Parameters
  • sys (StateSpace or TransferFunction) – LTI system to simulate

  • T (array_like, optional for discrete LTI sys) – Time steps at which the input is defined; values must be evenly spaced.

  • U (array_like or float, optional) –

    Input array giving input at each time T (default = 0).

    If U is None or 0, a special algorithm is used. This special algorithm is faster than the general algorithm, which is used otherwise.

  • X0 (array_like or float, optional) – Initial condition (default = 0).

  • transpose (bool, optional) – If True, transpose all input and output arrays (for backward compatibility with MATLAB and scipy.signal.lsim()). Default value is False.

  • interpolate (bool, optional (default=False)) – If True and system is a discrete time system, the input will be interpolated between the given time steps and the output will be given at system sampling rate. Otherwise, only return the output at the times given in T. No effect on continuous time simulations (default = False).

  • return_x (bool, optional) – If True (default), return the the state vector. Set to False to return only the time and output vectors.

  • squeeze (bool, optional) – By default, if a system is single-input, single-output (SISO) then the output response is returned as a 1D array (indexed by time). If squeeze=True, remove single-dimensional entries from the shape of the output even if the system is not SISO. If squeeze=False, keep the output as a 2D array (indexed by the output number and time) even if the system is SISO. The default value can be set using config.defaults[‘control.squeeze_time_response’].

Returns

  • T (array) – Time values of the output.

  • yout (array) – Response of the system. If the system is SISO and squeeze is not True, the array is 1D (indexed by time). If the system is not SISO or squeeze is False, the array is 2D (indexed by the output number and time).

  • xout (array) – Time evolution of the state vector. Not affected by squeeze.

Notes

For discrete time systems, the input/output response is computed using the scipy.signal.dlsim() function.

For continuous time systems, the output is computed using the matrix exponential exp(A t) and assuming linear interpolation of the inputs between time points.

Examples

>>> T, yout, xout = forced_response(sys, T, u, X0)

See Time series data.