@@ -1050,6 +1050,114 @@ def tb01pd(n, m, p, A, B, C, job='M', equil='S', tol=1e-8, ldwork=None):
10501050 raise e
10511051 return out [:- 1 ]
10521052
1053+ def tg01ad (l ,n ,m ,p ,A ,E ,B ,C ,thresh = 0.0 ,job = 'A' ):
1054+ """ A,E,B,C,lscale,rscale = tg01ad(l,n,m,p,A,E,B,C,[thresh,job])
1055+
1056+ To balance the matrices of the system pencil
1057+
1058+ S = ( A B ) - lambda ( E 0 ) := Q - lambda Z,
1059+ ( C 0 ) ( 0 0 )
1060+
1061+ corresponding to the descriptor triple (A-lambda E,B,C),
1062+ by balancing. This involves diagonal similarity transformations
1063+ (Dl*A*Dr - lambda Dl*E*Dr, Dl*B, C*Dr) applied to the system
1064+ (A-lambda E,B,C) to make the rows and columns of system pencil
1065+ matrices
1066+
1067+ diag(Dl,I) * S * diag(Dr,I)
1068+
1069+ as close in norm as possible. Balancing may reduce the 1-norms
1070+ of the matrices of the system pencil S.
1071+
1072+ The balancing can be performed optionally on the following
1073+ particular system pencils
1074+
1075+ S = A-lambda E,
1076+
1077+ S = ( A-lambda E B ), or
1078+
1079+ S = ( A-lambda E ).
1080+ ( C )
1081+ Required arguments:
1082+ l : input int
1083+ The number of rows of matrices A, B, and E. l >= 0.
1084+ n : input int
1085+ The number of columns of matrices A, E, and C. n >= 0.
1086+ m : input int
1087+ The number of columns of matrix B. m >= 0.
1088+ p : input int
1089+ The number of rows of matrix C. P >= 0.
1090+ A : rank-2 array('d') with bounds (l,n)
1091+ The leading L-by-N part of this array must
1092+ contain the state dynamics matrix A.
1093+ E : rank-2 array('d') with bounds (l,n)
1094+ The leading L-by-N part of this array must
1095+ contain the descriptor matrix E.
1096+ B : rank-2 array('d') with bounds (l,m)
1097+ The leading L-by-M part of this array must
1098+ contain the input/state matrix B.
1099+ The array B is not referenced if M = 0.
1100+ C : rank-2 array('d') with bounds (p,n)
1101+ The leading P-by-N part of this array must
1102+ contain the state/output matrix C.
1103+ The array C is not referenced if P = 0.
1104+ Optional arguments:
1105+ job := 'A' input string(len=1)
1106+ Indicates which matrices are involved in balancing, as
1107+ follows:
1108+ = 'A': All matrices are involved in balancing;
1109+ = 'B': B, A and E matrices are involved in balancing;
1110+ = 'C': C, A and E matrices are involved in balancing;
1111+ = 'N': B and C matrices are not involved in balancing.
1112+ thresh := 0.0 input float
1113+ Threshold value for magnitude of elements:
1114+ elements with magnitude less than or equal to
1115+ THRESH are ignored for balancing. THRESH >= 0.
1116+ Return objects:
1117+ A : rank-2 array('d') with bounds (l,n)
1118+ The leading L-by-N part of this array contains
1119+ the balanced matrix Dl*A*Dr.
1120+ E : rank-2 array('d') with bounds (l,n)
1121+ The leading L-by-N part of this array contains
1122+ the balanced matrix Dl*E*Dr.
1123+ B : rank-2 array('d') with bounds (l,m)
1124+ If M > 0, the leading L-by-M part of this array
1125+ contains the balanced matrix Dl*B.
1126+ The array B is not referenced if M = 0.
1127+ C : rank-2 array('d') with bounds (p,n)
1128+ If P > 0, the leading P-by-N part of this array
1129+ contains the balanced matrix C*Dr.
1130+ The array C is not referenced if P = 0.
1131+ lscale : rank-1 array('d') with bounds (l)
1132+ The scaling factors applied to S from left. If Dl(j) is
1133+ the scaling factor applied to row j, then
1134+ SCALE(j) = Dl(j), for j = 1,...,L.
1135+ rscale : rank-1 array('d') with bounds (n)
1136+ The scaling factors applied to S from right. If Dr(j) is
1137+ the scaling factor applied to column j, then
1138+ SCALE(j) = Dr(j), for j = 1,...,N.
1139+ """
1140+
1141+ hidden = ' (hidden by the wrapper)'
1142+ arg_list = ['job' , 'l' , 'n' , 'm' , 'p' , 'thresh' , 'A' , 'lda' + hidden , 'E' ,'lde' + hidden ,'B' ,'ldb' + hidden ,'C' ,'ldc' + hidden , 'lscale' , 'rscale' , 'dwork' + hidden , 'info' ]
1143+
1144+ if job != 'A' and job != 'B' and job != 'C' and job != 'N' :
1145+ raise ValueError ('Parameter job had an illegal value' )
1146+
1147+ A ,E ,B ,C ,lscale ,rscale ,info = _wrapper .tg01ad (job ,l ,n ,m ,p ,thresh ,A ,E ,B ,C )
1148+
1149+ if info < 0 :
1150+ error_text = "The following argument had an illegal value: " + arg_list [- info - 1 ]
1151+ e = ValueError (error_text )
1152+ e .info = info
1153+ raise e
1154+ if info != 0 :
1155+ e = ArithmeticError ('tg01ad failed' )
1156+ e .info = info
1157+ raise e
1158+
1159+ return A ,E ,B ,C ,lscale ,rscale
1160+
10531161def tg01fd (l ,n ,m ,p ,A ,E ,B ,C ,Q = None ,Z = None ,compq = 'N' ,compz = 'N' ,joba = 'N' ,tol = 0.0 ,ldwork = None ):
10541162 """ A,E,B,C,ranke,rnka22,Q,Z = tg01fd(l,n,m,p,A,E,B,C,[Q,Z,compq,compz,joba,tol,ldwork])
10551163
0 commit comments