alchemyst / Skogestad-Python

Python code for "Multivariable Feedback Control"
111 stars 88 forks source link

MIMO transfer function InternalDelay conversion results in IndexError: index 3 is out of bounds for axis 1 with size 3 #388

Closed jamestjsp closed 3 years ago

jamestjsp commented 3 years ago

from utils import InternalDelay, tf, mimotf

NoModel = tf([0], [1])

G11 = tf([0.0039 ], [85, 1], deadtime=85) G12 = NoModel G13 = NoModel G14 = tf([279.067728070848, 0.862100005149841], [7122.56780575453, 186.547394918102, 1],deadtime= 45) G15 = tf([0.009], [30, 1], deadtime=180) G16 = NoModel G21 = tf([0.0032], [160, 1], deadtime=85) G22 = tf([-0.1],[ 85, 1], deadtime=55) G23 = tf([-0.055], [160, 1], deadtime=100) G24 = NoModel G25 = NoModel G26 = NoModel G31 = tf([0.0033],[120, 1], deadtime=80) G32 = NoModel G33 = tf([-0.065], [120, 1], deadtime=95) G34 = NoModel G35 = NoModel G36 = NoModel

G = mimotf([ [G11, G12, G13, G14, G15, G16], [G21, G22, G23, G24, G25, G26], [G31, G32, G33, G34, G35, G36] ]) Gd = InternalDelay(G)

Running the above code will result in the following error.


Skogestad-Python\robustcontrol\InternalDelay.py:185: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray num, den, delays = [numpy.array(i) for i in [num, den, delays]] Traceback (most recent call last): File "c:\Users\user1\Documents\James\Skogestad-Python\robustcontrol\trasfer_func.py", line 33, in Gd = InternalDelay(G) File "C:\Users\user1\Documents\James\Skogestad-Python\robustcontrol\InternalDelay.py", line 81, in init matrices = InternalDelay.from_mimotf(sys).get_matrices() File "C:\Users\user1\Documents\James\Skogestad-Python\robustcontrol\InternalDelay.py", line 136, in from_mimotf return InternalDelay.from_tf_coefficients(num, den, delays) File "C:\Users\user1\Documents\James\Skogestad-Python\robustcontrol\InternalDelay.py", line 214, in from_tf_coefficients Gss_i = harold.transfer_to_state(harold.Transfer(num_i, den_i)) File "C:\Miniconda3\envs\control\lib\site-packages\harold_classes.py", line 2729, in transfer_to_state D[rows, cols] = num[rows][cols]/den[rows][cols] IndexError: index 3 is out of bounds for axis 1 with size 3

Observation: If I remove any one of the delay from first output (G11, G14 or G15) this error will not occur.

jamestjsp commented 3 years ago

The issue can be fixed by editing https://github.com/ilayn/harold/blob/90a785b44f45c9e05a5ef2da935f21c493e8448c/harold/_classes.py#L2883 D = np.empty((p, m), dtype=float)

alchemyst commented 3 years ago

Thank you for logging this error @jamestjsp. It seems as though this is actually an error in Harold rather than this repository? Might be good to register a pull request there?

jamestjsp commented 3 years ago

Ilhan Polat will fix it soon. Btw, this repository makes my life easier.