You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Possible bug: control.interconnect fails to construct a extended system with zero input and one output (D matrix shape mismatch) #1176
I attempted to simulate a control system with an output-feedback controller, defining a plant and a controller as subsystems.
When using control.interconnect to connect these subsystems, an error occurs because an extended system obtained by connecting subsystems has zero input and one output.
Is it impossible to define a system with zero input and one output using the control.interconnect function?
Error message
control.exception.ControlDimension: Incompatible dimensions of D matrix; expected (1, 0) but found (0, 0)
System information
OS: macOS Sonoma 14.3.1
Python: 3.12.2
python-control: 0.10.2
Cause of this problem
When we set the inputs and outputs of the extended system as zero input and one input, the D matrix of the extended system has (1, 0) dimension.
However, the dimension of D matrix is converted to (0, 0) dimension by _ssmatrix function at line 218 of statesp.py.
As a result, the mismatch of the dimensions occurs.
(When we set both inputs and outputs to zero, the error does not occur.)
I took a quick look and the problem is not with interconnect, but rather with the way StateSpace systems are initialized.
For whoever picks this one up, there is some code in _ssmatrix (used to preprocess state space matrices) that is converting the shape of the D matrix incorrectly:
elif (ndim == 2 and shape == (1, 0)) or \
(ndim == 1 and shape == (0, )):
# Passed an empty matrix or empty vector; change shape to (0, 0)
shape = (0, 0)
What is happening is that the D matrix for this example has shape (1, 0) [1 output, 0 inputs)] and it gets converted to shape (0, 0), causing an error. I think the fix is to also check the size of the array, so that [] and [[]] both get converted to an empty array (which is later cast to the correct shape in StateSpace.__init__).
Activity
murrayrm commentedon Jul 27, 2025
I took a quick look and the problem is not with
interconnect, but rather with the wayStateSpacesystems are initialized.For whoever picks this one up, there is some code in
_ssmatrix(used to preprocess state space matrices) that is converting the shape of theDmatrix incorrectly:What is happening is that the
Dmatrix for this example has shape (1, 0) [1 output, 0 inputs)] and it gets converted to shape (0, 0), causing an error. I think the fix is to also check thesizeof the array, so that[]and[[]]both get converted to an empty array (which is later cast to the correct shape inStateSpace.__init__).