StateSpace#
- class scipy.signal.StateSpace(*system, **kwargs)[source]#
Linear Time Invariant system in state-space form.
Represents the system as the continuous-time, first order differential equation \(\dot{x} = A x + B u\) or the discrete-time difference equation \(x[k+1] = A x[k] + B u[k]\).
StateSpacesystems inherit additional functionality from thelti, respectively thedlticlasses, depending on which system representation is used.- Parameters:
- *system: arguments
The
StateSpaceclass can be instantiated with 1 or 4 arguments. The following gives the number of input arguments and their interpretation:1:
ltiordltisystem: (StateSpace,TransferFunctionorZerosPolesGain)4: array_like: (A, B, C, D)
- dt: float, optional
Sampling time [s] of the discrete-time systems. Defaults to None (continuous-time). Must be specified as a keyword argument, for example,
dt=0.1.
- Attributes:
AState matrix of the
StateSpacesystem.BInput matrix of the
StateSpacesystem.COutput matrix of the
StateSpacesystem.DFeedthrough matrix of the
StateSpacesystem.dtReturn the sampling time of the system, None for
ltisystems.polesPoles of the system.
zerosZeros of the system.
Methods
__mul__(other)Post-multiply another system or a scalar
to_ss()Return a copy of the current
StateSpacesystem.to_tf(**kwargs)Convert system representation to
TransferFunction.to_zpk(**kwargs)Convert system representation to
ZerosPolesGain.See also
Notes
If the parameter system is a tuple (A, B, C, D) with four state space matrices, then those matrices are converted into two-dimensional arrays by calling
abcd_normalize. Their dtypes will be “complex128” if any of the matrices are complex-valued. Otherwise, they will be of type “float64”.Changing the value of properties that are not part of the
StateSpacesystem representation (such aszerosorpoles) is very inefficient and may lead to numerical inaccuracies. It is better to convert to the specific system representation first. For example, callsys = sys.to_zpk()before accessing/changing the zeros, poles or gain.The State-space system representation section of the SciPy User Guide presents the corresponding definitions of continuous-time and disrcete time state space systems.
Array API Standard Support
StateSpacehas experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variableSCIPY_ARRAY_API=1and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.Library
CPU
GPU
NumPy
✅
n/a
CuPy
n/a
⛔
PyTorch
⛔
⛔
JAX
⛔
⛔
Dask
⛔
n/a
See Support for the array API standard for more information.
Examples
>>> from scipy import signal >>> import numpy as np >>> a = np.array([[0, 1], [0, 0]]) >>> b = np.array([[0], [1]]) >>> c = np.array([[1, 0]]) >>> d = np.array([[0]])
>>> sys = signal.StateSpace(a, b, c, d) >>> print(sys) StateSpaceContinuous( array([[0., 1.], [0., 0.]]), array([[0.], [1.]]), array([[1., 0.]]), array([[0.]]), dt: None )
>>> sys.to_discrete(0.1) StateSpaceDiscrete( array([[1. , 0.1], [0. , 1. ]]), array([[0.005], [0.1 ]]), array([[1., 0.]]), array([[0.]]), dt: 0.1 )
>>> a = np.array([[1, 0.1], [0, 1]]) >>> b = np.array([[0.005], [0.1]])
>>> signal.StateSpace(a, b, c, d, dt=0.1) StateSpaceDiscrete( array([[1. , 0.1], [0. , 1. ]]), array([[0.005], [0.1 ]]), array([[1., 0.]]), array([[0.]]), dt: 0.1 )