ilayn / harold

An open-source systems and controls toolbox for Python3
MIT License
173 stars 19 forks source link

Getting exception when creating discrete MISO transfer function #64

Closed twmacro closed 4 years ago

twmacro commented 4 years ago

Hi!

I'm getting an error trying to create a discrete MISO transfer function. It easiest to show via code. This works:

import harold
print(harold.__version__)
print(harold.Transfer([[[1.0, 0.0]]], [[[1.0, 0.0]]], 0.02).polynomials)

Output:

1.0.2.dev0+517e57f
(array([[1., 0.]]), array([[1., 0.]]))

However, this does not work:

print(harold.Transfer([[[1.0], [1.0, 0.0]]], [[[1.0], [1.0, 0.0]]], 0.02).polynomials)

Output:

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-4-e546dfb4f959> in <module>
----> 1 print(harold.Transfer([[[1.0], [1.0, 0.0]]], [[[1.0], [1.0, 0.0]]], 0.02).polynomials)

~/anaconda3/envs/py38/lib/python3.8/site-packages/harold-1.0.2.dev0+517e57f-py3.8.egg/harold/_classes.py in __init__(self, num, den, dt)
     70         self._isdiscrete = False if dt is None else True
     71
---> 72         self._recalc()
     73
     74     @property

~/anaconda3/envs/py38/lib/python3.8/site-packages/harold-1.0.2.dev0+517e57f-py3.8.egg/harold/_classes.py in _recalc(self)
    301             else:
    302                 # Create a dummy statespace and check the zeros there
--> 303                 zzz = transfer_to_state((self._num, self._den),
    304                                         output='matrices')
    305                 self.zeros = transmission_zeros(*zzz)

~/anaconda3/envs/py38/lib/python3.8/site-packages/harold-1.0.2.dev0+517e57f-py3.8.egg/harold/_classes.py in transfer_to_state(G, output)
   2974             A = haroldcompanion(den[0][0])
   2975             B = np.zeros((A.shape[0], 1), dtype=float)
-> 2976             B[-1, 0] = 1.
   2977             t1, t2 = A, B
   2978

IndexError: index -1 is out of bounds for axis 0 with size 0
ilayn commented 4 years ago

Hi @twmacro thanks a lot for this. I'll try to take a look today but from the look of it indeed it's my stupidity and not an edge case :)

ilayn commented 4 years ago

I hope I fixed the error @twmacro. Thanks again for the bug report.

twmacro commented 4 years ago

Works like a charm! Thank you @ilayn!