Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

numerical issue creating transfer function #50

Closed
twmacro opened this issue Apr 24, 2019 · 3 comments · Fixed by #52
Closed

numerical issue creating transfer function #50

twmacro opened this issue Apr 24, 2019 · 3 comments · Fixed by #52
Labels
Milestone

Comments

@twmacro
Copy link

twmacro commented Apr 24, 2019

Hi!

I'm getting an error trying to create a transfer function. Below is a little example that shows the error on my computer. I'm thinking that somehow a numeric leading "zero" shows up (it was -8.3948810935738183e-17 for me) and is not trimmed off by np.trim_zeros. That creates sizing trouble when assembling the state-space matrices.

import harold


# set up a 2-input, 1-output transfer function

# denominator is the same for both transfer functions:
den = [[[[84.64, 18.4, 1.0]], [[1.0, 7.2, 144.0]]]]

# - same as below except last 4 digits chopped off for each number
num = [
    [
        [[61.7973249220, 36.2498843026, 0.730119623369]],
        [[0.037784067405, 0.997499379512, 21.76362282573]],
    ]
]

# this one works:
tf1 = harold.Transfer(num, den)
print(tf1)

# keep those last 4 digits and it breaks:
num = [
    [
        [[61.79732492202783, 36.24988430260625, 0.7301196233698941]],
        [[0.0377840674057878, 0.9974993795127982, 21.763622825733773]],
    ]
]

tf2 = harold.Transfer(num, den)
print(tf2)

And here is the output:

Continuous-Time Transfer function
 2 inputs and 1 output

  Poles(real)    Poles(imag)  Zeros(real)    Zeros(imag)
-------------  -------------  -------------  -------------
    -0.108696    1.16214e-07
    -0.108696   -1.16214e-07
    -3.6        11.4473
    -3.6       -11.4473


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
~/code/harold/bug.py in <module>
     27 ]
     28
---> 29 tf2 = harold.Transfer(num, den)
     30 print(tf2)

~/code/harold/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

~/code/harold/harold/_classes.py in _recalc(self)
    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)
    306                 self.poles = eigvals(zzz[0])

~/code/harold/harold/_classes.py in transfer_to_state(G, output)
   3036
   3037                 for row in range(p):
-> 3038                     C[row, k:k+num[row][col].size] = num[row][col][0, ::-1]
   3039                 k += coldegrees[col]
   3040

ValueError: could not broadcast input array from shape (5) into shape (4)
@ilayn
Copy link
Owner

ilayn commented Apr 25, 2019

Thanks @twmacro for taking the time. After briefly looking at it, I think your hunch is correct. I will take a look after work.

@twmacro
Copy link
Author

twmacro commented Apr 26, 2019

Fantastic! Thank you @ilayn!

@ilayn
Copy link
Owner

ilayn commented Apr 27, 2019

My pleasure @twmacro . Keep them coming:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants