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

bug when adding non-normalized transfer functions #47

Closed
twmacro opened this issue Mar 9, 2019 · 4 comments
Closed

bug when adding non-normalized transfer functions #47

twmacro opened this issue Mar 9, 2019 · 4 comments

Comments

@twmacro
Copy link

twmacro commented Mar 9, 2019

Hi!

Adding (110 s) / (85 s^2 + 20 s + 1) and 0.25 gives an incorrect result, but it works fine if the first transfer function is normalized. Here is a little example ... it shows that the numerator never gets divided by 85:

import numpy as np
import harold


num = np.array([110.0, 0.0])
den = np.array([85.0, 20.0, 1.0])

h_a = harold.Transfer(num, den)
h_b = harold.Transfer(num / 85.0, den / 85.0)

h2 = harold.Transfer(0.25, 1.0)

h_sum_a = h_a + h2
h_sum_b = h_b + h2
print(f"h_sum_a.num = {h_sum_a.num}")
print(f"h_sum_a.den = {h_sum_a.den}")

print()
print(f"h_sum_b.num = {h_sum_b.num}")
print(f"h_sum_b.den = {h_sum_b.den}")

The output is:

h_sum_a.num = [[2.50000000e-01 1.10058824e+02 2.94117647e-03]]
h_sum_a.den = [[1.         0.23529412 0.01176471]]

h_sum_b.num = [[0.25       1.35294118 0.00294118]]
h_sum_b.den = [[1.         0.23529412 0.01176471]]
@ilayn ilayn added this to the v1.0.2 milestone Mar 10, 2019
@ilayn
Copy link
Owner

ilayn commented Mar 10, 2019

Hi @twmacro Thank you for taking the time to report this. I am a bit disappointed that I didn't test this. I'll fix this and add some more tests hopefully today and push it.

@twmacro
Copy link
Author

twmacro commented Mar 10, 2019

Hi @ilayn, that's awesome! I really appreciate your quick turn-around. I'm making good use of harold! :-)

@ilayn
Copy link
Owner

ilayn commented Mar 11, 2019

Now it should be a bit more intuitive to add these things 😃 Note that, you can directly add scalars

import numpy as np
import harold


num = np.array([110.0, 0.0])
den = np.array([85.0, 20.0, 1.0])

h_a = harold.Transfer(num, den)
h_b = harold.Transfer(num / 85.0, den / 85.0)
h1 = h_a + 0.25
h2 = h_b + 0.25
print(f'Unscaled num: {h1.num}\nUnscaled den: {h1.den}')
print(f'scaled num:   {h2.num}\nscaled den:   {h2.den}')
print(f'Minimal realization: {harold.minimal_realization(h1).polynomials}')

This gives

Unscaled num: [[ 21.25 115.     0.25]]
Unscaled den: [[85. 20.  1.]]
scaled num:   [[0.25       1.35294118 0.00294118]]
scaled den:   [[1.         0.23529412 0.01176471]]
Minimal realization: (array([[0.25      , 1.35294118, 0.00294118]]), array([[1.        , 0.23529412, 0.01176471]]))

@twmacro
Copy link
Author

twmacro commented Mar 11, 2019

Fantastic, @ilayn! And many thanks for the usage tips -- I will make good use of them! 😃

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

No branches or pull requests

2 participants