1 *> \brief \b DLASY2 solves the Sylvester matrix equation where the matrices are of order 1 or 2.
3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download DLASY2 + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlasy2.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlasy2.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlasy2.f">
21 * SUBROUTINE DLASY2( LTRANL, LTRANR, ISGN, N1, N2, TL, LDTL, TR,
22 * LDTR, B, LDB, SCALE, X, LDX, XNORM, INFO )
24 * .. Scalar Arguments ..
25 * LOGICAL LTRANL, LTRANR
26 * INTEGER INFO, ISGN, LDB, LDTL, LDTR, LDX, N1, N2
27 * DOUBLE PRECISION SCALE, XNORM
29 * .. Array Arguments ..
30 * DOUBLE PRECISION B( LDB, * ), TL( LDTL, * ), TR( LDTR, * ),
40 *> DLASY2 solves for the N1 by N2 matrix X, 1 <= N1,N2 <= 2, in
42 *> op(TL)*X + ISGN*X*op(TR) = SCALE*B,
44 *> where TL is N1 by N1, TR is N2 by N2, B is N1 by N2, and ISGN = 1 or
45 *> -1. op(T) = T or T**T, where T**T denotes the transpose of T.
54 *> On entry, LTRANL specifies the op(TL):
55 *> = .FALSE., op(TL) = TL,
56 *> = .TRUE., op(TL) = TL**T.
62 *> On entry, LTRANR specifies the op(TR):
63 *> = .FALSE., op(TR) = TR,
64 *> = .TRUE., op(TR) = TR**T.
70 *> On entry, ISGN specifies the sign of the equation
71 *> as described before. ISGN may only be 1 or -1.
77 *> On entry, N1 specifies the order of matrix TL.
78 *> N1 may only be 0, 1 or 2.
84 *> On entry, N2 specifies the order of matrix TR.
85 *> N2 may only be 0, 1 or 2.
90 *> TL is DOUBLE PRECISION array, dimension (LDTL,2)
91 *> On entry, TL contains an N1 by N1 matrix.
97 *> The leading dimension of the matrix TL. LDTL >= max(1,N1).
102 *> TR is DOUBLE PRECISION array, dimension (LDTR,2)
103 *> On entry, TR contains an N2 by N2 matrix.
109 *> The leading dimension of the matrix TR. LDTR >= max(1,N2).
114 *> B is DOUBLE PRECISION array, dimension (LDB,2)
115 *> On entry, the N1 by N2 matrix B contains the right-hand
116 *> side of the equation.
122 *> The leading dimension of the matrix B. LDB >= max(1,N1).
127 *> SCALE is DOUBLE PRECISION
128 *> On exit, SCALE contains the scale factor. SCALE is chosen
129 *> less than or equal to 1 to prevent the solution overflowing.
134 *> X is DOUBLE PRECISION array, dimension (LDX,2)
135 *> On exit, X contains the N1 by N2 solution.
141 *> The leading dimension of the matrix X. LDX >= max(1,N1).
146 *> XNORM is DOUBLE PRECISION
147 *> On exit, XNORM is the infinity-norm of the solution.
153 *> On exit, INFO is set to
154 *> 0: successful exit.
155 *> 1: TL and TR have too close eigenvalues, so TL or
156 *> TR is perturbed to get a nonsingular equation.
157 *> NOTE: In the interests of speed, this routine does not
158 *> check the inputs for errors.
164 *> \author Univ. of Tennessee
165 *> \author Univ. of California Berkeley
166 *> \author Univ. of Colorado Denver
171 *> \ingroup doubleSYauxiliary
173 * =====================================================================
174 SUBROUTINE DLASY2( LTRANL, LTRANR, ISGN, N1, N2, TL, LDTL, TR,
175 $ LDTR, B, LDB, SCALE, X, LDX, XNORM, INFO )
177 * -- LAPACK auxiliary routine (version 3.6.1) --
178 * -- LAPACK is a software package provided by Univ. of Tennessee, --
179 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
182 * .. Scalar Arguments ..
183 LOGICAL LTRANL, LTRANR
184 INTEGER INFO, ISGN, LDB, LDTL, LDTR, LDX, N1, N2
185 DOUBLE PRECISION SCALE, XNORM
187 * .. Array Arguments ..
188 DOUBLE PRECISION B( LDB, * ), TL( LDTL, * ), TR( LDTR, * ),
192 * =====================================================================
195 DOUBLE PRECISION ZERO, ONE
196 PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
197 DOUBLE PRECISION TWO, HALF, EIGHT
198 PARAMETER ( TWO = 2.0D+0, HALF = 0.5D+0, EIGHT = 8.0D+0 )
200 * .. Local Scalars ..
202 INTEGER I, IP, IPIV, IPSV, J, JP, JPSV, K
203 DOUBLE PRECISION BET, EPS, GAM, L21, SGN, SMIN, SMLNUM, TAU1,
204 $ TEMP, U11, U12, U22, XMAX
207 LOGICAL BSWPIV( 4 ), XSWPIV( 4 )
208 INTEGER JPIV( 4 ), LOCL21( 4 ), LOCU12( 4 ),
210 DOUBLE PRECISION BTMP( 4 ), T16( 4, 4 ), TMP( 4 ), X2( 2 )
212 * .. External Functions ..
214 DOUBLE PRECISION DLAMCH
215 EXTERNAL IDAMAX, DLAMCH
217 * .. External Subroutines ..
218 EXTERNAL DCOPY, DSWAP
220 * .. Intrinsic Functions ..
223 * .. Data statements ..
224 DATA LOCU12 / 3, 4, 1, 2 / , LOCL21 / 2, 1, 4, 3 / ,
225 $ LOCU22 / 4, 3, 2, 1 /
226 DATA XSWPIV / .FALSE., .FALSE., .TRUE., .TRUE. /
227 DATA BSWPIV / .FALSE., .TRUE., .FALSE., .TRUE. /
229 * .. Executable Statements ..
231 * Do not check the input parameters for errors
235 * Quick return if possible
237 IF( N1.EQ.0 .OR. N2.EQ.0 )
240 * Set constants to control overflow
243 SMLNUM = DLAMCH( 'S' ) / EPS
247 GO TO ( 10, 20, 30, 50 )K
249 * 1 by 1: TL11*X + SGN*X*TR11 = B11
252 TAU1 = TL( 1, 1 ) + SGN*TR( 1, 1 )
254 IF( BET.LE.SMLNUM ) THEN
261 GAM = ABS( B( 1, 1 ) )
262 IF( SMLNUM*GAM.GT.BET )
265 X( 1, 1 ) = ( B( 1, 1 )*SCALE ) / TAU1
266 XNORM = ABS( X( 1, 1 ) )
270 * TL11*[X11 X12] + ISGN*[X11 X12]*op[TR11 TR12] = [B11 B12]
275 SMIN = MAX( EPS*MAX( ABS( TL( 1, 1 ) ), ABS( TR( 1, 1 ) ),
276 $ ABS( TR( 1, 2 ) ), ABS( TR( 2, 1 ) ), ABS( TR( 2, 2 ) ) ),
278 TMP( 1 ) = TL( 1, 1 ) + SGN*TR( 1, 1 )
279 TMP( 4 ) = TL( 1, 1 ) + SGN*TR( 2, 2 )
281 TMP( 2 ) = SGN*TR( 2, 1 )
282 TMP( 3 ) = SGN*TR( 1, 2 )
284 TMP( 2 ) = SGN*TR( 1, 2 )
285 TMP( 3 ) = SGN*TR( 2, 1 )
287 BTMP( 1 ) = B( 1, 1 )
288 BTMP( 2 ) = B( 1, 2 )
292 * op[TL11 TL12]*[X11] + ISGN* [X11]*TR11 = [B11]
293 * [TL21 TL22] [X21] [X21] [B21]
296 SMIN = MAX( EPS*MAX( ABS( TR( 1, 1 ) ), ABS( TL( 1, 1 ) ),
297 $ ABS( TL( 1, 2 ) ), ABS( TL( 2, 1 ) ), ABS( TL( 2, 2 ) ) ),
299 TMP( 1 ) = TL( 1, 1 ) + SGN*TR( 1, 1 )
300 TMP( 4 ) = TL( 2, 2 ) + SGN*TR( 1, 1 )
302 TMP( 2 ) = TL( 1, 2 )
303 TMP( 3 ) = TL( 2, 1 )
305 TMP( 2 ) = TL( 2, 1 )
306 TMP( 3 ) = TL( 1, 2 )
308 BTMP( 1 ) = B( 1, 1 )
309 BTMP( 2 ) = B( 2, 1 )
312 * Solve 2 by 2 system using complete pivoting.
313 * Set pivots less than SMIN to SMIN.
315 IPIV = IDAMAX( 4, TMP, 1 )
317 IF( ABS( U11 ).LE.SMIN ) THEN
321 U12 = TMP( LOCU12( IPIV ) )
322 L21 = TMP( LOCL21( IPIV ) ) / U11
323 U22 = TMP( LOCU22( IPIV ) ) - U12*L21
324 XSWAP = XSWPIV( IPIV )
325 BSWAP = BSWPIV( IPIV )
326 IF( ABS( U22 ).LE.SMIN ) THEN
332 BTMP( 2 ) = BTMP( 1 ) - L21*TEMP
335 BTMP( 2 ) = BTMP( 2 ) - L21*BTMP( 1 )
338 IF( ( TWO*SMLNUM )*ABS( BTMP( 2 ) ).GT.ABS( U22 ) .OR.
339 $ ( TWO*SMLNUM )*ABS( BTMP( 1 ) ).GT.ABS( U11 ) ) THEN
340 SCALE = HALF / MAX( ABS( BTMP( 1 ) ), ABS( BTMP( 2 ) ) )
341 BTMP( 1 ) = BTMP( 1 )*SCALE
342 BTMP( 2 ) = BTMP( 2 )*SCALE
344 X2( 2 ) = BTMP( 2 ) / U22
345 X2( 1 ) = BTMP( 1 ) / U11 - ( U12 / U11 )*X2( 2 )
354 XNORM = ABS( X( 1, 1 ) ) + ABS( X( 1, 2 ) )
357 XNORM = MAX( ABS( X( 1, 1 ) ), ABS( X( 2, 1 ) ) )
362 * op[TL11 TL12]*[X11 X12] +ISGN* [X11 X12]*op[TR11 TR12] = [B11 B12]
363 * [TL21 TL22] [X21 X22] [X21 X22] [TR21 TR22] [B21 B22]
365 * Solve equivalent 4 by 4 system using complete pivoting.
366 * Set pivots less than SMIN to SMIN.
369 SMIN = MAX( ABS( TR( 1, 1 ) ), ABS( TR( 1, 2 ) ),
370 $ ABS( TR( 2, 1 ) ), ABS( TR( 2, 2 ) ) )
371 SMIN = MAX( SMIN, ABS( TL( 1, 1 ) ), ABS( TL( 1, 2 ) ),
372 $ ABS( TL( 2, 1 ) ), ABS( TL( 2, 2 ) ) )
373 SMIN = MAX( EPS*SMIN, SMLNUM )
375 CALL DCOPY( 16, BTMP, 0, T16, 1 )
376 T16( 1, 1 ) = TL( 1, 1 ) + SGN*TR( 1, 1 )
377 T16( 2, 2 ) = TL( 2, 2 ) + SGN*TR( 1, 1 )
378 T16( 3, 3 ) = TL( 1, 1 ) + SGN*TR( 2, 2 )
379 T16( 4, 4 ) = TL( 2, 2 ) + SGN*TR( 2, 2 )
381 T16( 1, 2 ) = TL( 2, 1 )
382 T16( 2, 1 ) = TL( 1, 2 )
383 T16( 3, 4 ) = TL( 2, 1 )
384 T16( 4, 3 ) = TL( 1, 2 )
386 T16( 1, 2 ) = TL( 1, 2 )
387 T16( 2, 1 ) = TL( 2, 1 )
388 T16( 3, 4 ) = TL( 1, 2 )
389 T16( 4, 3 ) = TL( 2, 1 )
392 T16( 1, 3 ) = SGN*TR( 1, 2 )
393 T16( 2, 4 ) = SGN*TR( 1, 2 )
394 T16( 3, 1 ) = SGN*TR( 2, 1 )
395 T16( 4, 2 ) = SGN*TR( 2, 1 )
397 T16( 1, 3 ) = SGN*TR( 2, 1 )
398 T16( 2, 4 ) = SGN*TR( 2, 1 )
399 T16( 3, 1 ) = SGN*TR( 1, 2 )
400 T16( 4, 2 ) = SGN*TR( 1, 2 )
402 BTMP( 1 ) = B( 1, 1 )
403 BTMP( 2 ) = B( 2, 1 )
404 BTMP( 3 ) = B( 1, 2 )
405 BTMP( 4 ) = B( 2, 2 )
407 * Perform elimination
413 IF( ABS( T16( IP, JP ) ).GE.XMAX ) THEN
414 XMAX = ABS( T16( IP, JP ) )
421 CALL DSWAP( 4, T16( IPSV, 1 ), 4, T16( I, 1 ), 4 )
423 BTMP( I ) = BTMP( IPSV )
427 $ CALL DSWAP( 4, T16( 1, JPSV ), 1, T16( 1, I ), 1 )
429 IF( ABS( T16( I, I ) ).LT.SMIN ) THEN
434 T16( J, I ) = T16( J, I ) / T16( I, I )
435 BTMP( J ) = BTMP( J ) - T16( J, I )*BTMP( I )
437 T16( J, K ) = T16( J, K ) - T16( J, I )*T16( I, K )
441 IF( ABS( T16( 4, 4 ) ).LT.SMIN ) THEN
446 IF( ( EIGHT*SMLNUM )*ABS( BTMP( 1 ) ).GT.ABS( T16( 1, 1 ) ) .OR.
447 $ ( EIGHT*SMLNUM )*ABS( BTMP( 2 ) ).GT.ABS( T16( 2, 2 ) ) .OR.
448 $ ( EIGHT*SMLNUM )*ABS( BTMP( 3 ) ).GT.ABS( T16( 3, 3 ) ) .OR.
449 $ ( EIGHT*SMLNUM )*ABS( BTMP( 4 ) ).GT.ABS( T16( 4, 4 ) ) ) THEN
450 SCALE = ( ONE / EIGHT ) / MAX( ABS( BTMP( 1 ) ),
451 $ ABS( BTMP( 2 ) ), ABS( BTMP( 3 ) ), ABS( BTMP( 4 ) ) )
452 BTMP( 1 ) = BTMP( 1 )*SCALE
453 BTMP( 2 ) = BTMP( 2 )*SCALE
454 BTMP( 3 ) = BTMP( 3 )*SCALE
455 BTMP( 4 ) = BTMP( 4 )*SCALE
459 TEMP = ONE / T16( K, K )
460 TMP( K ) = BTMP( K )*TEMP
462 TMP( K ) = TMP( K ) - ( TEMP*T16( K, J ) )*TMP( J )
466 IF( JPIV( 4-I ).NE.4-I ) THEN
468 TMP( 4-I ) = TMP( JPIV( 4-I ) )
469 TMP( JPIV( 4-I ) ) = TEMP
476 XNORM = MAX( ABS( TMP( 1 ) )+ABS( TMP( 3 ) ),
477 $ ABS( TMP( 2 ) )+ABS( TMP( 4 ) ) )