Skip to content

Commit fb1e905

Browse files
committed
BugFix: allow minreal on static gain StateSpace objects
Do this by only calling Slycot's tb01pd for non-static systems.
1 parent 2794260 commit fb1e905

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

control/statesp.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -471,18 +471,22 @@ def feedback(self, other=1, sign=-1):
471471
def minreal(self, tol=0.0):
472472
"""Calculate a minimal realization, removes unobservable and
473473
uncontrollable states"""
474-
try:
475-
from slycot import tb01pd
476-
B = empty((self.states, max(self.inputs, self.outputs)))
477-
B[:,:self.inputs] = self.B
478-
C = empty((max(self.outputs, self.inputs), self.states))
479-
C[:self.outputs,:] = self.C
480-
A, B, C, nr = tb01pd(self.states, self.inputs, self.outputs,
481-
self.A, B, C, tol=tol)
482-
return StateSpace(A[:nr,:nr], B[:nr,:self.inputs],
483-
C[:self.outputs,:nr], self.D)
484-
except ImportError:
485-
raise TypeError("minreal requires slycot tb01pd")
474+
if self.states:
475+
try:
476+
from slycot import tb01pd
477+
B = empty((self.states, max(self.inputs, self.outputs)))
478+
B[:,:self.inputs] = self.B
479+
C = empty((max(self.outputs, self.inputs), self.states))
480+
C[:self.outputs,:] = self.C
481+
A, B, C, nr = tb01pd(self.states, self.inputs, self.outputs,
482+
self.A, B, C, tol=tol)
483+
return StateSpace(A[:nr,:nr], B[:nr,:self.inputs],
484+
C[:self.outputs,:nr], self.D)
485+
except ImportError:
486+
raise TypeError("minreal requires slycot tb01pd")
487+
else:
488+
return StateSpace(self)
489+
486490

487491
# TODO: add discrete time check
488492
def returnScipySignalLTI(self):

control/tests/statesp_test.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,17 @@ def test_BadEmptyMatrices(self):
297297
self.assertRaises(ValueError,StateSpace, [], [], [1], [1])
298298
self.assertRaises(ValueError,StateSpace, [1], [1], [1], [])
299299

300+
301+
def test_minrealStaticGain(self):
302+
"""Regression: minreal on static gain was failing"""
303+
g1 = StateSpace([],[],[],[1])
304+
g2 = g1.minreal()
305+
np.testing.assert_array_equal(g1.A, g2.A)
306+
np.testing.assert_array_equal(g1.B, g2.B)
307+
np.testing.assert_array_equal(g1.C, g2.C)
308+
np.testing.assert_array_equal(g1.D, g2.D)
309+
310+
300311
class TestRss(unittest.TestCase):
301312
"""These are tests for the proper functionality of statesp.rss."""
302313

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy