3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download DTGSYL + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dtgsyl.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dtgsyl.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dtgsyl.f">
21 * SUBROUTINE DTGSYL( TRANS, IJOB, M, N, A, LDA, B, LDB, C, LDC, D,
22 * LDD, E, LDE, F, LDF, SCALE, DIF, WORK, LWORK,
25 * .. Scalar Arguments ..
27 * INTEGER IJOB, INFO, LDA, LDB, LDC, LDD, LDE, LDF,
29 * DOUBLE PRECISION DIF, SCALE
31 * .. Array Arguments ..
33 * DOUBLE PRECISION A( LDA, * ), B( LDB, * ), C( LDC, * ),
34 * $ D( LDD, * ), E( LDE, * ), F( LDF, * ),
44 *> DTGSYL solves the generalized Sylvester equation:
46 *> A * R - L * B = scale * C (1)
47 *> D * R - L * E = scale * F
49 *> where R and L are unknown m-by-n matrices, (A, D), (B, E) and
50 *> (C, F) are given matrix pairs of size m-by-m, n-by-n and m-by-n,
51 *> respectively, with real entries. (A, D) and (B, E) must be in
52 *> generalized (real) Schur canonical form, i.e. A, B are upper quasi
53 *> triangular and D, E are upper triangular.
55 *> The solution (R, L) overwrites (C, F). 0 <= SCALE <= 1 is an output
56 *> scaling factor chosen to avoid overflow.
58 *> In matrix notation (1) is equivalent to solve Zx = scale b, where
61 *> Z = [ kron(In, A) -kron(B**T, Im) ] (2)
62 *> [ kron(In, D) -kron(E**T, Im) ].
64 *> Here Ik is the identity matrix of size k and X**T is the transpose of
65 *> X. kron(X, Y) is the Kronecker product between the matrices X and Y.
67 *> If TRANS = 'T', DTGSYL solves the transposed system Z**T*y = scale*b,
68 *> which is equivalent to solve for R and L in
70 *> A**T * R + D**T * L = scale * C (3)
71 *> R * B**T + L * E**T = scale * -F
73 *> This case (TRANS = 'T') is used to compute an one-norm-based estimate
74 *> of Dif[(A,D), (B,E)], the separation between the matrix pairs (A,D)
75 *> and (B,E), using DLACON.
77 *> If IJOB >= 1, DTGSYL computes a Frobenius norm-based estimate
78 *> of Dif[(A,D),(B,E)]. That is, the reciprocal of a lower bound on the
79 *> reciprocal of the smallest singular value of Z. See [1-2] for more
82 *> This is a level 3 BLAS algorithm.
90 *> TRANS is CHARACTER*1
91 *> = 'N', solve the generalized Sylvester equation (1).
92 *> = 'T', solve the 'transposed' system (3).
98 *> Specifies what kind of functionality to be performed.
99 *> =0: solve (1) only.
100 *> =1: The functionality of 0 and 3.
101 *> =2: The functionality of 0 and 4.
102 *> =3: Only an estimate of Dif[(A,D), (B,E)] is computed.
103 *> (look ahead strategy IJOB = 1 is used).
104 *> =4: Only an estimate of Dif[(A,D), (B,E)] is computed.
105 *> ( DGECON on sub-systems is used ).
106 *> Not referenced if TRANS = 'T'.
112 *> The order of the matrices A and D, and the row dimension of
113 *> the matrices C, F, R and L.
119 *> The order of the matrices B and E, and the column dimension
120 *> of the matrices C, F, R and L.
125 *> A is DOUBLE PRECISION array, dimension (LDA, M)
126 *> The upper quasi triangular matrix A.
132 *> The leading dimension of the array A. LDA >= max(1, M).
137 *> B is DOUBLE PRECISION array, dimension (LDB, N)
138 *> The upper quasi triangular matrix B.
144 *> The leading dimension of the array B. LDB >= max(1, N).
149 *> C is DOUBLE PRECISION array, dimension (LDC, N)
150 *> On entry, C contains the right-hand-side of the first matrix
151 *> equation in (1) or (3).
152 *> On exit, if IJOB = 0, 1 or 2, C has been overwritten by
153 *> the solution R. If IJOB = 3 or 4 and TRANS = 'N', C holds R,
154 *> the solution achieved during the computation of the
161 *> The leading dimension of the array C. LDC >= max(1, M).
166 *> D is DOUBLE PRECISION array, dimension (LDD, M)
167 *> The upper triangular matrix D.
173 *> The leading dimension of the array D. LDD >= max(1, M).
178 *> E is DOUBLE PRECISION array, dimension (LDE, N)
179 *> The upper triangular matrix E.
185 *> The leading dimension of the array E. LDE >= max(1, N).
190 *> F is DOUBLE PRECISION array, dimension (LDF, N)
191 *> On entry, F contains the right-hand-side of the second matrix
192 *> equation in (1) or (3).
193 *> On exit, if IJOB = 0, 1 or 2, F has been overwritten by
194 *> the solution L. If IJOB = 3 or 4 and TRANS = 'N', F holds L,
195 *> the solution achieved during the computation of the
202 *> The leading dimension of the array F. LDF >= max(1, M).
207 *> DIF is DOUBLE PRECISION
208 *> On exit DIF is the reciprocal of a lower bound of the
209 *> reciprocal of the Dif-function, i.e. DIF is an upper bound of
210 *> Dif[(A,D), (B,E)] = sigma_min(Z), where Z as in (2).
211 *> IF IJOB = 0 or TRANS = 'T', DIF is not touched.
216 *> SCALE is DOUBLE PRECISION
217 *> On exit SCALE is the scaling factor in (1) or (3).
218 *> If 0 < SCALE < 1, C and F hold the solutions R and L, resp.,
219 *> to a slightly perturbed system but the input matrices A, B, D
220 *> and E have not been changed. If SCALE = 0, C and F hold the
221 *> solutions R and L, respectively, to the homogeneous system
222 *> with C = F = 0. Normally, SCALE = 1.
227 *> WORK is DOUBLE PRECISION array, dimension (MAX(1,LWORK))
228 *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
234 *> The dimension of the array WORK. LWORK > = 1.
235 *> If IJOB = 1 or 2 and TRANS = 'N', LWORK >= max(1,2*M*N).
237 *> If LWORK = -1, then a workspace query is assumed; the routine
238 *> only calculates the optimal size of the WORK array, returns
239 *> this value as the first entry of the WORK array, and no error
240 *> message related to LWORK is issued by XERBLA.
245 *> IWORK is INTEGER array, dimension (M+N+6)
251 *> =0: successful exit
252 *> <0: If INFO = -i, the i-th argument had an illegal value.
253 *> >0: (A, D) and (B, E) have common or close eigenvalues.
259 *> \author Univ. of Tennessee
260 *> \author Univ. of California Berkeley
261 *> \author Univ. of Colorado Denver
264 *> \date November 2011
266 *> \ingroup doubleSYcomputational
268 *> \par Contributors:
271 *> Bo Kagstrom and Peter Poromaa, Department of Computing Science,
272 *> Umea University, S-901 87 Umea, Sweden.
279 *> [1] B. Kagstrom and P. Poromaa, LAPACK-Style Algorithms and Software
280 *> for Solving the Generalized Sylvester Equation and Estimating the
281 *> Separation between Regular Matrix Pairs, Report UMINF - 93.23,
282 *> Department of Computing Science, Umea University, S-901 87 Umea,
283 *> Sweden, December 1993, Revised April 1994, Also as LAPACK Working
284 *> Note 75. To appear in ACM Trans. on Math. Software, Vol 22,
287 *> [2] B. Kagstrom, A Perturbation Analysis of the Generalized Sylvester
288 *> Equation (AR - LB, DR - LE ) = (C, F), SIAM J. Matrix Anal.
289 *> Appl., 15(4):1045-1060, 1994
291 *> [3] B. Kagstrom and L. Westin, Generalized Schur Methods with
292 *> Condition Estimators for Solving the Generalized Sylvester
293 *> Equation, IEEE Transactions on Automatic Control, Vol. 34, No. 7,
294 *> July 1989, pp 745-751.
297 * =====================================================================
298 SUBROUTINE DTGSYL( TRANS, IJOB, M, N, A, LDA, B, LDB, C, LDC, D,
299 $ LDD, E, LDE, F, LDF, SCALE, DIF, WORK, LWORK,
302 * -- LAPACK computational routine (version 3.4.0) --
303 * -- LAPACK is a software package provided by Univ. of Tennessee, --
304 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
307 * .. Scalar Arguments ..
309 INTEGER IJOB, INFO, LDA, LDB, LDC, LDD, LDE, LDF,
311 DOUBLE PRECISION DIF, SCALE
313 * .. Array Arguments ..
315 DOUBLE PRECISION A( LDA, * ), B( LDB, * ), C( LDC, * ),
316 $ D( LDD, * ), E( LDE, * ), F( LDF, * ),
320 * =====================================================================
321 * Replaced various illegal calls to DCOPY by calls to DLASET.
322 * Sven Hammarling, 1/5/02.
325 DOUBLE PRECISION ZERO, ONE
326 PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
328 * .. Local Scalars ..
329 LOGICAL LQUERY, NOTRAN
330 INTEGER I, IE, IFUNC, IROUND, IS, ISOLVE, J, JE, JS, K,
331 $ LINFO, LWMIN, MB, NB, P, PPQQ, PQ, Q
332 DOUBLE PRECISION DSCALE, DSUM, SCALE2, SCALOC
334 * .. External Functions ..
337 EXTERNAL LSAME, ILAENV
339 * .. External Subroutines ..
340 EXTERNAL DGEMM, DLACPY, DLASET, DSCAL, DTGSY2, XERBLA
342 * .. Intrinsic Functions ..
343 INTRINSIC DBLE, MAX, SQRT
345 * .. Executable Statements ..
347 * Decode and test input parameters
350 NOTRAN = LSAME( TRANS, 'N' )
351 LQUERY = ( LWORK.EQ.-1 )
353 IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) ) THEN
355 ELSE IF( NOTRAN ) THEN
356 IF( ( IJOB.LT.0 ) .OR. ( IJOB.GT.4 ) ) THEN
363 ELSE IF( N.LE.0 ) THEN
365 ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
367 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
369 ELSE IF( LDC.LT.MAX( 1, M ) ) THEN
371 ELSE IF( LDD.LT.MAX( 1, M ) ) THEN
373 ELSE IF( LDE.LT.MAX( 1, N ) ) THEN
375 ELSE IF( LDF.LT.MAX( 1, M ) ) THEN
382 IF( IJOB.EQ.1 .OR. IJOB.EQ.2 ) THEN
383 LWMIN = MAX( 1, 2*M*N )
392 IF( LWORK.LT.LWMIN .AND. .NOT.LQUERY ) THEN
398 CALL XERBLA( 'DTGSYL', -INFO )
400 ELSE IF( LQUERY ) THEN
404 * Quick return if possible
406 IF( M.EQ.0 .OR. N.EQ.0 ) THEN
416 * Determine optimal block sizes MB and NB
418 MB = ILAENV( 2, 'DTGSYL', TRANS, M, N, -1, -1 )
419 NB = ILAENV( 5, 'DTGSYL', TRANS, M, N, -1, -1 )
426 CALL DLASET( 'F', M, N, ZERO, ZERO, C, LDC )
427 CALL DLASET( 'F', M, N, ZERO, ZERO, F, LDF )
428 ELSE IF( IJOB.GE.1 ) THEN
433 IF( ( MB.LE.1 .AND. NB.LE.1 ) .OR. ( MB.GE.M .AND. NB.GE.N ) )
436 DO 30 IROUND = 1, ISOLVE
438 * Use unblocked Level 2 solver
443 CALL DTGSY2( TRANS, IFUNC, M, N, A, LDA, B, LDB, C, LDC, D,
444 $ LDD, E, LDE, F, LDF, SCALE, DSUM, DSCALE,
446 IF( DSCALE.NE.ZERO ) THEN
447 IF( IJOB.EQ.1 .OR. IJOB.EQ.3 ) THEN
448 DIF = SQRT( DBLE( 2*M*N ) ) / ( DSCALE*SQRT( DSUM ) )
450 DIF = SQRT( DBLE( PQ ) ) / ( DSCALE*SQRT( DSUM ) )
454 IF( ISOLVE.EQ.2 .AND. IROUND.EQ.1 ) THEN
459 CALL DLACPY( 'F', M, N, C, LDC, WORK, M )
460 CALL DLACPY( 'F', M, N, F, LDF, WORK( M*N+1 ), M )
461 CALL DLASET( 'F', M, N, ZERO, ZERO, C, LDC )
462 CALL DLASET( 'F', M, N, ZERO, ZERO, F, LDF )
463 ELSE IF( ISOLVE.EQ.2 .AND. IROUND.EQ.2 ) THEN
464 CALL DLACPY( 'F', M, N, WORK, M, C, LDC )
465 CALL DLACPY( 'F', M, N, WORK( M*N+1 ), M, F, LDF )
473 * Determine block structure of A
485 IF( A( I, I-1 ).NE.ZERO )
491 IF( IWORK( P ).EQ.IWORK( P+1 ) )
494 * Determine block structure of B
506 IF( B( J, J-1 ).NE.ZERO )
512 IF( IWORK( Q ).EQ.IWORK( Q+1 ) )
517 DO 150 IROUND = 1, ISOLVE
519 * Solve (I, J)-subsystem
520 * A(I, I) * R(I, J) - L(I, J) * B(J, J) = C(I, J)
521 * D(I, I) * R(I, J) - L(I, J) * E(J, J) = F(I, J)
522 * for I = P, P - 1,..., 1; J = 1, 2,..., Q
530 JE = IWORK( J+1 ) - 1
534 IE = IWORK( I+1 ) - 1
537 CALL DTGSY2( TRANS, IFUNC, MB, NB, A( IS, IS ), LDA,
538 $ B( JS, JS ), LDB, C( IS, JS ), LDC,
539 $ D( IS, IS ), LDD, E( JS, JS ), LDE,
540 $ F( IS, JS ), LDF, SCALOC, DSUM, DSCALE,
541 $ IWORK( Q+2 ), PPQQ, LINFO )
546 IF( SCALOC.NE.ONE ) THEN
548 CALL DSCAL( M, SCALOC, C( 1, K ), 1 )
549 CALL DSCAL( M, SCALOC, F( 1, K ), 1 )
552 CALL DSCAL( IS-1, SCALOC, C( 1, K ), 1 )
553 CALL DSCAL( IS-1, SCALOC, F( 1, K ), 1 )
556 CALL DSCAL( M-IE, SCALOC, C( IE+1, K ), 1 )
557 CALL DSCAL( M-IE, SCALOC, F( IE+1, K ), 1 )
560 CALL DSCAL( M, SCALOC, C( 1, K ), 1 )
561 CALL DSCAL( M, SCALOC, F( 1, K ), 1 )
566 * Substitute R(I, J) and L(I, J) into remaining
570 CALL DGEMM( 'N', 'N', IS-1, NB, MB, -ONE,
571 $ A( 1, IS ), LDA, C( IS, JS ), LDC, ONE,
573 CALL DGEMM( 'N', 'N', IS-1, NB, MB, -ONE,
574 $ D( 1, IS ), LDD, C( IS, JS ), LDC, ONE,
578 CALL DGEMM( 'N', 'N', MB, N-JE, NB, ONE,
579 $ F( IS, JS ), LDF, B( JS, JE+1 ), LDB,
580 $ ONE, C( IS, JE+1 ), LDC )
581 CALL DGEMM( 'N', 'N', MB, N-JE, NB, ONE,
582 $ F( IS, JS ), LDF, E( JS, JE+1 ), LDE,
583 $ ONE, F( IS, JE+1 ), LDF )
587 IF( DSCALE.NE.ZERO ) THEN
588 IF( IJOB.EQ.1 .OR. IJOB.EQ.3 ) THEN
589 DIF = SQRT( DBLE( 2*M*N ) ) / ( DSCALE*SQRT( DSUM ) )
591 DIF = SQRT( DBLE( PQ ) ) / ( DSCALE*SQRT( DSUM ) )
594 IF( ISOLVE.EQ.2 .AND. IROUND.EQ.1 ) THEN
599 CALL DLACPY( 'F', M, N, C, LDC, WORK, M )
600 CALL DLACPY( 'F', M, N, F, LDF, WORK( M*N+1 ), M )
601 CALL DLASET( 'F', M, N, ZERO, ZERO, C, LDC )
602 CALL DLASET( 'F', M, N, ZERO, ZERO, F, LDF )
603 ELSE IF( ISOLVE.EQ.2 .AND. IROUND.EQ.2 ) THEN
604 CALL DLACPY( 'F', M, N, WORK, M, C, LDC )
605 CALL DLACPY( 'F', M, N, WORK( M*N+1 ), M, F, LDF )
612 * Solve transposed (I, J)-subsystem
613 * A(I, I)**T * R(I, J) + D(I, I)**T * L(I, J) = C(I, J)
614 * R(I, J) * B(J, J)**T + L(I, J) * E(J, J)**T = -F(I, J)
615 * for I = 1,2,..., P; J = Q, Q-1,..., 1
620 IE = IWORK( I+1 ) - 1
622 DO 200 J = Q, P + 2, -1
624 JE = IWORK( J+1 ) - 1
626 CALL DTGSY2( TRANS, IFUNC, MB, NB, A( IS, IS ), LDA,
627 $ B( JS, JS ), LDB, C( IS, JS ), LDC,
628 $ D( IS, IS ), LDD, E( JS, JS ), LDE,
629 $ F( IS, JS ), LDF, SCALOC, DSUM, DSCALE,
630 $ IWORK( Q+2 ), PPQQ, LINFO )
633 IF( SCALOC.NE.ONE ) THEN
635 CALL DSCAL( M, SCALOC, C( 1, K ), 1 )
636 CALL DSCAL( M, SCALOC, F( 1, K ), 1 )
639 CALL DSCAL( IS-1, SCALOC, C( 1, K ), 1 )
640 CALL DSCAL( IS-1, SCALOC, F( 1, K ), 1 )
643 CALL DSCAL( M-IE, SCALOC, C( IE+1, K ), 1 )
644 CALL DSCAL( M-IE, SCALOC, F( IE+1, K ), 1 )
647 CALL DSCAL( M, SCALOC, C( 1, K ), 1 )
648 CALL DSCAL( M, SCALOC, F( 1, K ), 1 )
653 * Substitute R(I, J) and L(I, J) into remaining equation.
656 CALL DGEMM( 'N', 'T', MB, JS-1, NB, ONE, C( IS, JS ),
657 $ LDC, B( 1, JS ), LDB, ONE, F( IS, 1 ),
659 CALL DGEMM( 'N', 'T', MB, JS-1, NB, ONE, F( IS, JS ),
660 $ LDF, E( 1, JS ), LDE, ONE, F( IS, 1 ),
664 CALL DGEMM( 'T', 'N', M-IE, NB, MB, -ONE,
665 $ A( IS, IE+1 ), LDA, C( IS, JS ), LDC, ONE,
666 $ C( IE+1, JS ), LDC )
667 CALL DGEMM( 'T', 'N', M-IE, NB, MB, -ONE,
668 $ D( IS, IE+1 ), LDD, F( IS, JS ), LDF, ONE,
669 $ C( IE+1, JS ), LDC )