slaln2.f
来自「famous linear algebra library (LAPACK) p」· F 代码 · 共 508 行 · 第 1/2 页
F
508 行
SUBROUTINE SLALN2( LTRANS, NA, NW, SMIN, CA, A, LDA, D1, D2, B,
$ LDB, WR, WI, X, LDX, SCALE, XNORM, INFO )
*
* -- LAPACK auxiliary routine (version 3.1) --
* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
* November 2006
*
* .. Scalar Arguments ..
LOGICAL LTRANS
INTEGER INFO, LDA, LDB, LDX, NA, NW
REAL CA, D1, D2, SCALE, SMIN, WI, WR, XNORM
* ..
* .. Array Arguments ..
REAL A( LDA, * ), B( LDB, * ), X( LDX, * )
* ..
*
* Purpose
* =======
*
* SLALN2 solves a system of the form (ca A - w D ) X = s B
* or (ca A' - w D) X = s B with possible scaling ("s") and
* perturbation of A. (A' means A-transpose.)
*
* A is an NA x NA real matrix, ca is a real scalar, D is an NA x NA
* real diagonal matrix, w is a real or complex value, and X and B are
* NA x 1 matrices -- real if w is real, complex if w is complex. NA
* may be 1 or 2.
*
* If w is complex, X and B are represented as NA x 2 matrices,
* the first column of each being the real part and the second
* being the imaginary part.
*
* "s" is a scaling factor (.LE. 1), computed by SLALN2, which is
* so chosen that X can be computed without overflow. X is further
* scaled if necessary to assure that norm(ca A - w D)*norm(X) is less
* than overflow.
*
* If both singular values of (ca A - w D) are less than SMIN,
* SMIN*identity will be used instead of (ca A - w D). If only one
* singular value is less than SMIN, one element of (ca A - w D) will be
* perturbed enough to make the smallest singular value roughly SMIN.
* If both singular values are at least SMIN, (ca A - w D) will not be
* perturbed. In any case, the perturbation will be at most some small
* multiple of max( SMIN, ulp*norm(ca A - w D) ). The singular values
* are computed by infinity-norm approximations, and thus will only be
* correct to a factor of 2 or so.
*
* Note: all input quantities are assumed to be smaller than overflow
* by a reasonable factor. (See BIGNUM.)
*
* Arguments
* ==========
*
* LTRANS (input) LOGICAL
* =.TRUE.: A-transpose will be used.
* =.FALSE.: A will be used (not transposed.)
*
* NA (input) INTEGER
* The size of the matrix A. It may (only) be 1 or 2.
*
* NW (input) INTEGER
* 1 if "w" is real, 2 if "w" is complex. It may only be 1
* or 2.
*
* SMIN (input) REAL
* The desired lower bound on the singular values of A. This
* should be a safe distance away from underflow or overflow,
* say, between (underflow/machine precision) and (machine
* precision * overflow ). (See BIGNUM and ULP.)
*
* CA (input) REAL
* The coefficient c, which A is multiplied by.
*
* A (input) REAL array, dimension (LDA,NA)
* The NA x NA matrix A.
*
* LDA (input) INTEGER
* The leading dimension of A. It must be at least NA.
*
* D1 (input) REAL
* The 1,1 element in the diagonal matrix D.
*
* D2 (input) REAL
* The 2,2 element in the diagonal matrix D. Not used if NW=1.
*
* B (input) REAL array, dimension (LDB,NW)
* The NA x NW matrix B (right-hand side). If NW=2 ("w" is
* complex), column 1 contains the real part of B and column 2
* contains the imaginary part.
*
* LDB (input) INTEGER
* The leading dimension of B. It must be at least NA.
*
* WR (input) REAL
* The real part of the scalar "w".
*
* WI (input) REAL
* The imaginary part of the scalar "w". Not used if NW=1.
*
* X (output) REAL array, dimension (LDX,NW)
* The NA x NW matrix X (unknowns), as computed by SLALN2.
* If NW=2 ("w" is complex), on exit, column 1 will contain
* the real part of X and column 2 will contain the imaginary
* part.
*
* LDX (input) INTEGER
* The leading dimension of X. It must be at least NA.
*
* SCALE (output) REAL
* The scale factor that B must be multiplied by to insure
* that overflow does not occur when computing X. Thus,
* (ca A - w D) X will be SCALE*B, not B (ignoring
* perturbations of A.) It will be at most 1.
*
* XNORM (output) REAL
* The infinity-norm of X, when X is regarded as an NA x NW
* real matrix.
*
* INFO (output) INTEGER
* An error flag. It will be set to zero if no error occurs,
* a negative number if an argument is in error, or a positive
* number if ca A - w D had to be perturbed.
* The possible values are:
* = 0: No error occurred, and (ca A - w D) did not have to be
* perturbed.
* = 1: (ca A - w D) had to be perturbed to make its smallest
* (or only) singular value greater than SMIN.
* NOTE: In the interests of speed, this routine does not
* check the inputs for errors.
*
* =====================================================================
*
* .. Parameters ..
REAL ZERO, ONE
PARAMETER ( ZERO = 0.0E0, ONE = 1.0E0 )
REAL TWO
PARAMETER ( TWO = 2.0E0 )
* ..
* .. Local Scalars ..
INTEGER ICMAX, J
REAL BBND, BI1, BI2, BIGNUM, BNORM, BR1, BR2, CI21,
$ CI22, CMAX, CNORM, CR21, CR22, CSI, CSR, LI21,
$ LR21, SMINI, SMLNUM, TEMP, U22ABS, UI11, UI11R,
$ UI12, UI12S, UI22, UR11, UR11R, UR12, UR12S,
$ UR22, XI1, XI2, XR1, XR2
* ..
* .. Local Arrays ..
LOGICAL CSWAP( 4 ), RSWAP( 4 )
INTEGER IPIVOT( 4, 4 )
REAL CI( 2, 2 ), CIV( 4 ), CR( 2, 2 ), CRV( 4 )
* ..
* .. External Functions ..
REAL SLAMCH
EXTERNAL SLAMCH
* ..
* .. External Subroutines ..
EXTERNAL SLADIV
* ..
* .. Intrinsic Functions ..
INTRINSIC ABS, MAX
* ..
* .. Equivalences ..
EQUIVALENCE ( CI( 1, 1 ), CIV( 1 ) ),
$ ( CR( 1, 1 ), CRV( 1 ) )
* ..
* .. Data statements ..
DATA CSWAP / .FALSE., .FALSE., .TRUE., .TRUE. /
DATA RSWAP / .FALSE., .TRUE., .FALSE., .TRUE. /
DATA IPIVOT / 1, 2, 3, 4, 2, 1, 4, 3, 3, 4, 1, 2, 4,
$ 3, 2, 1 /
* ..
* .. Executable Statements ..
*
* Compute BIGNUM
*
SMLNUM = TWO*SLAMCH( 'Safe minimum' )
BIGNUM = ONE / SMLNUM
SMINI = MAX( SMIN, SMLNUM )
*
* Don't check for input errors
*
INFO = 0
*
* Standard Initializations
*
SCALE = ONE
*
IF( NA.EQ.1 ) THEN
*
* 1 x 1 (i.e., scalar) system C X = B
*
IF( NW.EQ.1 ) THEN
*
* Real 1x1 system.
*
* C = ca A - w D
*
CSR = CA*A( 1, 1 ) - WR*D1
CNORM = ABS( CSR )
*
* If | C | < SMINI, use C = SMINI
*
IF( CNORM.LT.SMINI ) THEN
CSR = SMINI
CNORM = SMINI
INFO = 1
END IF
*
* Check scaling for X = B / C
*
BNORM = ABS( B( 1, 1 ) )
IF( CNORM.LT.ONE .AND. BNORM.GT.ONE ) THEN
IF( BNORM.GT.BIGNUM*CNORM )
$ SCALE = ONE / BNORM
END IF
*
* Compute X
*
X( 1, 1 ) = ( B( 1, 1 )*SCALE ) / CSR
XNORM = ABS( X( 1, 1 ) )
ELSE
*
* Complex 1x1 system (w is complex)
*
* C = ca A - w D
*
CSR = CA*A( 1, 1 ) - WR*D1
CSI = -WI*D1
CNORM = ABS( CSR ) + ABS( CSI )
*
* If | C | < SMINI, use C = SMINI
*
IF( CNORM.LT.SMINI ) THEN
CSR = SMINI
CSI = ZERO
CNORM = SMINI
INFO = 1
END IF
*
* Check scaling for X = B / C
*
BNORM = ABS( B( 1, 1 ) ) + ABS( B( 1, 2 ) )
IF( CNORM.LT.ONE .AND. BNORM.GT.ONE ) THEN
IF( BNORM.GT.BIGNUM*CNORM )
$ SCALE = ONE / BNORM
END IF
*
* Compute X
*
CALL SLADIV( SCALE*B( 1, 1 ), SCALE*B( 1, 2 ), CSR, CSI,
$ X( 1, 1 ), X( 1, 2 ) )
XNORM = ABS( X( 1, 1 ) ) + ABS( X( 1, 2 ) )
END IF
*
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?