Skip to content

Commit f70d941

Browse files
committed
fixed problem with minreal when reduction leaves only a gain and no zeros;
poly([]) would return 1 instead of the expected array([1.])
1 parent c03ee45 commit f70d941

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

src/matlab.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
from control.ctrlutil import unwrap
9797
from control.freqplot import nyquist, gangof4
9898
from control.nichols import nichols
99-
from control.bdalg import series, parallel, negate, feedback
99+
from control.bdalg import series, parallel, negate, feedback, append
100100
from control.pzmap import pzmap
101101
from control.statefbk import ctrb, obsv, gram, place, lqr
102102
from control.delay import pade

src/xferfcn.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,8 +661,12 @@ def minreal(self, tol=None):
661661
newzeros.append(z)
662662

663663
# keep result
664-
num[i][j] = gain * real(poly(newzeros))
664+
if len(newzeros):
665+
num[i][j] = gain * real(poly(newzeros))
666+
else:
667+
num[i][j] = array([gain])
665668
den[i][j] = real(poly(poles))
669+
666670

667671
# end result
668672
return TransferFunction(num, den)

tests/xferfcn_test.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,19 @@ def testMinreal(self):
444444
np.testing.assert_array_almost_equal(hm.num[0][0], hr.num[0][0])
445445
np.testing.assert_array_almost_equal(hm.den[0][0], hr.den[0][0])
446446

447+
def testMinreal2(self):
448+
"""This one gave a problem, due to poly([]) giving simply 1
449+
instead of numpy.array([1])"""
450+
s = TransferFunction([1, 0], [1])
451+
G = 6205/(s*(s**2 + 13*s + 1281))
452+
Heq = G.feedback(1)
453+
H1 = 1/(s+5)
454+
H2a = Heq/H1
455+
H2b = H2a.minreal()
456+
hr = 6205/(s**2+8*s+1241)
457+
np.testing.assert_array_almost_equal(H2b.num[0][0], hr.num[0][0])
458+
np.testing.assert_array_almost_equal(H2b.den[0][0], hr.den[0][0])
459+
447460
def testMIMO(self):
448461
"""Test conversion of a single input, two-output state-space
449462
system against the same TF"""

0 commit comments

Comments
 (0)