Skip to content

Commit fca28a3

Browse files
committed
fix for DGEBAL transformation application, issue python-control#11
1 parent 429989b commit fca28a3

3 files changed

Lines changed: 30 additions & 5 deletions

File tree

‎slycot/src/TB01TD.f‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ SUBROUTINE TB01TD( N, M, P, A, LDA, B, LDB, C, LDC, D, LDD, LOW,
245245
C to transform B and C.
246246
C
247247
DO 10 K = 1, N
248-
KOLD = K
248+
KOLD = N + 1 - K ! RvP, rabraker, slycot #11
249249
IF ( ( LOW.GT.KOLD ) .OR. ( KOLD.GT.IGH ) ) THEN
250250
IF ( KOLD.LT.LOW ) KOLD = LOW - KOLD
251251
KNEW = INT( SCSTAT(KOLD) )

‎slycot/src/TB05AD.f‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,10 @@ SUBROUTINE TB05AD( BALEIG, INITA, N, M, P, FREQ, A, LDA, B, LDB,
346346
C defined in the subroutine DGEBAL.
347347
C
348348
DO 10 J = 1, N
349-
JJ = J
349+
JJ = N + 1 - J ! RvP, rabraker, slycot #11
350350
IF ( JJ.LT.LOW .OR. JJ.GT.IGH ) THEN
351351
IF ( JJ.LT.LOW ) JJ = LOW - JJ
352-
JP = DWORK(JJ)
352+
JP = INT( DWORK(JJ) )
353353
IF ( JP.NE.JJ ) THEN
354354
C
355355
C Permute rows of B.

‎slycot/tests/test_tb05ad.py‎

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from numpy.testing import assert_almost_equal
1212

1313

14+
1415
# set the random seed so we can get consistent results.
1516
np.random.seed(40)
1617
CASES = {}
@@ -47,9 +48,10 @@ def test_tb05ad_ng(self):
4748
for key in CASES:
4849
sys = CASES[key]
4950
self.check_tb05ad_AG_NG(sys, 10*1j, 'NG')
51+
self.check_tb05ad_AG_NG(sys, 10*1j, 'AG')
5052

51-
@unittest.expectedFailure
52-
def test_tb05ad_ag_failure(self):
53+
#@unittest.expectedFailure
54+
def test_tb05ad_ag_no_longer_failure(self):
5355
""" Test tb05ad and job 'AG' (i.e., balancing enabled) fails
5456
on certain A matrices.
5557
"""
@@ -187,6 +189,29 @@ def test_tb05ad_resonance(self):
187189
transform.tb05ad(2, 1, 1, jomega, A, B, C, job='NH')
188190
assert cm.exception.info == 2
189191

192+
def test_tb05ad_balance(self):
193+
"""Specifically check for the balancing output.
194+
195+
Based on https://rdrr.io/rforge/expm/man/balance.html
196+
"""
197+
A = np.array(((-1, -1, 0, 0),
198+
( 0, 0, 10, 10),
199+
( 0, 0, 10, 0),
200+
( 0, 10, 0, 0)), dtype=float)
201+
B = np.eye(4)
202+
C = np.eye(4)
203+
Ar = np.array(((-1, -1, 0, 0),
204+
( 0, 0, 10, 10),
205+
( 0, 10, 0, 0),
206+
( 0, 0, 0, 10)))
207+
jomega = 1.0
208+
At, Bt, Ct, rcond, g_jw, ev, hinvb, info = transform.tb05ad(
209+
4, 4, 4, jomega, A, B, C, job='AG')
210+
assert_almost_equal(At, Ar)
211+
212+
At, Bt, Ct, rcond, g_jwb, ev, hinvb, info = transform.tb05ad(
213+
4, 4, 4, jomega, A, B, C, job='AG')
214+
190215

191216
if __name__ == "__main__":
192217
unittest.main()

0 commit comments

Comments
 (0)