00001 /* zpbsvx.f -- translated by f2c (version 20061008). 00002 You must link the resulting object file with libf2c: 00003 on Microsoft Windows system, link with libf2c.lib; 00004 on Linux or Unix systems, link with .../path/to/libf2c.a -lm 00005 or, if you install libf2c.a in a standard place, with -lf2c -lm 00006 -- in that order, at the end of the command line, as in 00007 cc *.o -lf2c -lm 00008 Source for libf2c is in /netlib/f2c/libf2c.zip, e.g., 00009 00010 http://www.netlib.org/f2c/libf2c.zip 00011 */ 00012 00013 #include "f2c.h" 00014 #include "blaswrap.h" 00015 00016 /* Table of constant values */ 00017 00018 static integer c__1 = 1; 00019 00020 /* Subroutine */ int zpbsvx_(char *fact, char *uplo, integer *n, integer *kd, 00021 integer *nrhs, doublecomplex *ab, integer *ldab, doublecomplex *afb, 00022 integer *ldafb, char *equed, doublereal *s, doublecomplex *b, integer 00023 *ldb, doublecomplex *x, integer *ldx, doublereal *rcond, doublereal * 00024 ferr, doublereal *berr, doublecomplex *work, doublereal *rwork, 00025 integer *info) 00026 { 00027 /* System generated locals */ 00028 integer ab_dim1, ab_offset, afb_dim1, afb_offset, b_dim1, b_offset, 00029 x_dim1, x_offset, i__1, i__2, i__3, i__4, i__5; 00030 doublereal d__1, d__2; 00031 doublecomplex z__1; 00032 00033 /* Local variables */ 00034 integer i__, j, j1, j2; 00035 doublereal amax, smin, smax; 00036 extern logical lsame_(char *, char *); 00037 doublereal scond, anorm; 00038 logical equil, rcequ, upper; 00039 extern /* Subroutine */ int zcopy_(integer *, doublecomplex *, integer *, 00040 doublecomplex *, integer *); 00041 extern doublereal dlamch_(char *); 00042 logical nofact; 00043 extern /* Subroutine */ int xerbla_(char *, integer *); 00044 extern doublereal zlanhb_(char *, char *, integer *, integer *, 00045 doublecomplex *, integer *, doublereal *); 00046 doublereal bignum; 00047 extern /* Subroutine */ int zlaqhb_(char *, integer *, integer *, 00048 doublecomplex *, integer *, doublereal *, doublereal *, 00049 doublereal *, char *); 00050 integer infequ; 00051 extern /* Subroutine */ int zpbcon_(char *, integer *, integer *, 00052 doublecomplex *, integer *, doublereal *, doublereal *, 00053 doublecomplex *, doublereal *, integer *), zlacpy_(char *, 00054 integer *, integer *, doublecomplex *, integer *, doublecomplex * 00055 , integer *), zpbequ_(char *, integer *, integer *, 00056 doublecomplex *, integer *, doublereal *, doublereal *, 00057 doublereal *, integer *), zpbrfs_(char *, integer *, 00058 integer *, integer *, doublecomplex *, integer *, doublecomplex *, 00059 integer *, doublecomplex *, integer *, doublecomplex *, integer * 00060 , doublereal *, doublereal *, doublecomplex *, doublereal *, 00061 integer *), zpbtrf_(char *, integer *, integer *, 00062 doublecomplex *, integer *, integer *); 00063 doublereal smlnum; 00064 extern /* Subroutine */ int zpbtrs_(char *, integer *, integer *, integer 00065 *, doublecomplex *, integer *, doublecomplex *, integer *, 00066 integer *); 00067 00068 00069 /* -- LAPACK driver routine (version 3.2) -- */ 00070 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ 00071 /* November 2006 */ 00072 00073 /* .. Scalar Arguments .. */ 00074 /* .. */ 00075 /* .. Array Arguments .. */ 00076 /* .. */ 00077 00078 /* Purpose */ 00079 /* ======= */ 00080 00081 /* ZPBSVX uses the Cholesky factorization A = U**H*U or A = L*L**H to */ 00082 /* compute the solution to a complex system of linear equations */ 00083 /* A * X = B, */ 00084 /* where A is an N-by-N Hermitian positive definite band matrix and X */ 00085 /* and B are N-by-NRHS matrices. */ 00086 00087 /* Error bounds on the solution and a condition estimate are also */ 00088 /* provided. */ 00089 00090 /* Description */ 00091 /* =========== */ 00092 00093 /* The following steps are performed: */ 00094 00095 /* 1. If FACT = 'E', real scaling factors are computed to equilibrate */ 00096 /* the system: */ 00097 /* diag(S) * A * diag(S) * inv(diag(S)) * X = diag(S) * B */ 00098 /* Whether or not the system will be equilibrated depends on the */ 00099 /* scaling of the matrix A, but if equilibration is used, A is */ 00100 /* overwritten by diag(S)*A*diag(S) and B by diag(S)*B. */ 00101 00102 /* 2. If FACT = 'N' or 'E', the Cholesky decomposition is used to */ 00103 /* factor the matrix A (after equilibration if FACT = 'E') as */ 00104 /* A = U**H * U, if UPLO = 'U', or */ 00105 /* A = L * L**H, if UPLO = 'L', */ 00106 /* where U is an upper triangular band matrix, and L is a lower */ 00107 /* triangular band matrix. */ 00108 00109 /* 3. If the leading i-by-i principal minor is not positive definite, */ 00110 /* then the routine returns with INFO = i. Otherwise, the factored */ 00111 /* form of A is used to estimate the condition number of the matrix */ 00112 /* A. If the reciprocal of the condition number is less than machine */ 00113 /* precision, INFO = N+1 is returned as a warning, but the routine */ 00114 /* still goes on to solve for X and compute error bounds as */ 00115 /* described below. */ 00116 00117 /* 4. The system of equations is solved for X using the factored form */ 00118 /* of A. */ 00119 00120 /* 5. Iterative refinement is applied to improve the computed solution */ 00121 /* matrix and calculate error bounds and backward error estimates */ 00122 /* for it. */ 00123 00124 /* 6. If equilibration was used, the matrix X is premultiplied by */ 00125 /* diag(S) so that it solves the original system before */ 00126 /* equilibration. */ 00127 00128 /* Arguments */ 00129 /* ========= */ 00130 00131 /* FACT (input) CHARACTER*1 */ 00132 /* Specifies whether or not the factored form of the matrix A is */ 00133 /* supplied on entry, and if not, whether the matrix A should be */ 00134 /* equilibrated before it is factored. */ 00135 /* = 'F': On entry, AFB contains the factored form of A. */ 00136 /* If EQUED = 'Y', the matrix A has been equilibrated */ 00137 /* with scaling factors given by S. AB and AFB will not */ 00138 /* be modified. */ 00139 /* = 'N': The matrix A will be copied to AFB and factored. */ 00140 /* = 'E': The matrix A will be equilibrated if necessary, then */ 00141 /* copied to AFB and factored. */ 00142 00143 /* UPLO (input) CHARACTER*1 */ 00144 /* = 'U': Upper triangle of A is stored; */ 00145 /* = 'L': Lower triangle of A is stored. */ 00146 00147 /* N (input) INTEGER */ 00148 /* The number of linear equations, i.e., the order of the */ 00149 /* matrix A. N >= 0. */ 00150 00151 /* KD (input) INTEGER */ 00152 /* The number of superdiagonals of the matrix A if UPLO = 'U', */ 00153 /* or the number of subdiagonals if UPLO = 'L'. KD >= 0. */ 00154 00155 /* NRHS (input) INTEGER */ 00156 /* The number of right-hand sides, i.e., the number of columns */ 00157 /* of the matrices B and X. NRHS >= 0. */ 00158 00159 /* AB (input/output) COMPLEX*16 array, dimension (LDAB,N) */ 00160 /* On entry, the upper or lower triangle of the Hermitian band */ 00161 /* matrix A, stored in the first KD+1 rows of the array, except */ 00162 /* if FACT = 'F' and EQUED = 'Y', then A must contain the */ 00163 /* equilibrated matrix diag(S)*A*diag(S). The j-th column of A */ 00164 /* is stored in the j-th column of the array AB as follows: */ 00165 /* if UPLO = 'U', AB(KD+1+i-j,j) = A(i,j) for max(1,j-KD)<=i<=j; */ 00166 /* if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(N,j+KD). */ 00167 /* See below for further details. */ 00168 00169 /* On exit, if FACT = 'E' and EQUED = 'Y', A is overwritten by */ 00170 /* diag(S)*A*diag(S). */ 00171 00172 /* LDAB (input) INTEGER */ 00173 /* The leading dimension of the array A. LDAB >= KD+1. */ 00174 00175 /* AFB (input or output) COMPLEX*16 array, dimension (LDAFB,N) */ 00176 /* If FACT = 'F', then AFB is an input argument and on entry */ 00177 /* contains the triangular factor U or L from the Cholesky */ 00178 /* factorization A = U**H*U or A = L*L**H of the band matrix */ 00179 /* A, in the same storage format as A (see AB). If EQUED = 'Y', */ 00180 /* then AFB is the factored form of the equilibrated matrix A. */ 00181 00182 /* If FACT = 'N', then AFB is an output argument and on exit */ 00183 /* returns the triangular factor U or L from the Cholesky */ 00184 /* factorization A = U**H*U or A = L*L**H. */ 00185 00186 /* If FACT = 'E', then AFB is an output argument and on exit */ 00187 /* returns the triangular factor U or L from the Cholesky */ 00188 /* factorization A = U**H*U or A = L*L**H of the equilibrated */ 00189 /* matrix A (see the description of A for the form of the */ 00190 /* equilibrated matrix). */ 00191 00192 /* LDAFB (input) INTEGER */ 00193 /* The leading dimension of the array AFB. LDAFB >= KD+1. */ 00194 00195 /* EQUED (input or output) CHARACTER*1 */ 00196 /* Specifies the form of equilibration that was done. */ 00197 /* = 'N': No equilibration (always true if FACT = 'N'). */ 00198 /* = 'Y': Equilibration was done, i.e., A has been replaced by */ 00199 /* diag(S) * A * diag(S). */ 00200 /* EQUED is an input argument if FACT = 'F'; otherwise, it is an */ 00201 /* output argument. */ 00202 00203 /* S (input or output) DOUBLE PRECISION array, dimension (N) */ 00204 /* The scale factors for A; not accessed if EQUED = 'N'. S is */ 00205 /* an input argument if FACT = 'F'; otherwise, S is an output */ 00206 /* argument. If FACT = 'F' and EQUED = 'Y', each element of S */ 00207 /* must be positive. */ 00208 00209 /* B (input/output) COMPLEX*16 array, dimension (LDB,NRHS) */ 00210 /* On entry, the N-by-NRHS right hand side matrix B. */ 00211 /* On exit, if EQUED = 'N', B is not modified; if EQUED = 'Y', */ 00212 /* B is overwritten by diag(S) * B. */ 00213 00214 /* LDB (input) INTEGER */ 00215 /* The leading dimension of the array B. LDB >= max(1,N). */ 00216 00217 /* X (output) COMPLEX*16 array, dimension (LDX,NRHS) */ 00218 /* If INFO = 0 or INFO = N+1, the N-by-NRHS solution matrix X to */ 00219 /* the original system of equations. Note that if EQUED = 'Y', */ 00220 /* A and B are modified on exit, and the solution to the */ 00221 /* equilibrated system is inv(diag(S))*X. */ 00222 00223 /* LDX (input) INTEGER */ 00224 /* The leading dimension of the array X. LDX >= max(1,N). */ 00225 00226 /* RCOND (output) DOUBLE PRECISION */ 00227 /* The estimate of the reciprocal condition number of the matrix */ 00228 /* A after equilibration (if done). If RCOND is less than the */ 00229 /* machine precision (in particular, if RCOND = 0), the matrix */ 00230 /* is singular to working precision. This condition is */ 00231 /* indicated by a return code of INFO > 0. */ 00232 00233 /* FERR (output) DOUBLE PRECISION array, dimension (NRHS) */ 00234 /* The estimated forward error bound for each solution vector */ 00235 /* X(j) (the j-th column of the solution matrix X). */ 00236 /* If XTRUE is the true solution corresponding to X(j), FERR(j) */ 00237 /* is an estimated upper bound for the magnitude of the largest */ 00238 /* element in (X(j) - XTRUE) divided by the magnitude of the */ 00239 /* largest element in X(j). The estimate is as reliable as */ 00240 /* the estimate for RCOND, and is almost always a slight */ 00241 /* overestimate of the true error. */ 00242 00243 /* BERR (output) DOUBLE PRECISION array, dimension (NRHS) */ 00244 /* The componentwise relative backward error of each solution */ 00245 /* vector X(j) (i.e., the smallest relative change in */ 00246 /* any element of A or B that makes X(j) an exact solution). */ 00247 00248 /* WORK (workspace) COMPLEX*16 array, dimension (2*N) */ 00249 00250 /* RWORK (workspace) DOUBLE PRECISION array, dimension (N) */ 00251 00252 /* INFO (output) INTEGER */ 00253 /* = 0: successful exit */ 00254 /* < 0: if INFO = -i, the i-th argument had an illegal value */ 00255 /* > 0: if INFO = i, and i is */ 00256 /* <= N: the leading minor of order i of A is */ 00257 /* not positive definite, so the factorization */ 00258 /* could not be completed, and the solution has not */ 00259 /* been computed. RCOND = 0 is returned. */ 00260 /* = N+1: U is nonsingular, but RCOND is less than machine */ 00261 /* precision, meaning that the matrix is singular */ 00262 /* to working precision. Nevertheless, the */ 00263 /* solution and error bounds are computed because */ 00264 /* there are a number of situations where the */ 00265 /* computed solution can be more accurate than the */ 00266 /* value of RCOND would suggest. */ 00267 00268 /* Further Details */ 00269 /* =============== */ 00270 00271 /* The band storage scheme is illustrated by the following example, when */ 00272 /* N = 6, KD = 2, and UPLO = 'U': */ 00273 00274 /* Two-dimensional storage of the Hermitian matrix A: */ 00275 00276 /* a11 a12 a13 */ 00277 /* a22 a23 a24 */ 00278 /* a33 a34 a35 */ 00279 /* a44 a45 a46 */ 00280 /* a55 a56 */ 00281 /* (aij=conjg(aji)) a66 */ 00282 00283 /* Band storage of the upper triangle of A: */ 00284 00285 /* * * a13 a24 a35 a46 */ 00286 /* * a12 a23 a34 a45 a56 */ 00287 /* a11 a22 a33 a44 a55 a66 */ 00288 00289 /* Similarly, if UPLO = 'L' the format of A is as follows: */ 00290 00291 /* a11 a22 a33 a44 a55 a66 */ 00292 /* a21 a32 a43 a54 a65 * */ 00293 /* a31 a42 a53 a64 * * */ 00294 00295 /* Array elements marked * are not used by the routine. */ 00296 00297 /* ===================================================================== */ 00298 00299 /* .. Parameters .. */ 00300 /* .. */ 00301 /* .. Local Scalars .. */ 00302 /* .. */ 00303 /* .. External Functions .. */ 00304 /* .. */ 00305 /* .. External Subroutines .. */ 00306 /* .. */ 00307 /* .. Intrinsic Functions .. */ 00308 /* .. */ 00309 /* .. Executable Statements .. */ 00310 00311 /* Parameter adjustments */ 00312 ab_dim1 = *ldab; 00313 ab_offset = 1 + ab_dim1; 00314 ab -= ab_offset; 00315 afb_dim1 = *ldafb; 00316 afb_offset = 1 + afb_dim1; 00317 afb -= afb_offset; 00318 --s; 00319 b_dim1 = *ldb; 00320 b_offset = 1 + b_dim1; 00321 b -= b_offset; 00322 x_dim1 = *ldx; 00323 x_offset = 1 + x_dim1; 00324 x -= x_offset; 00325 --ferr; 00326 --berr; 00327 --work; 00328 --rwork; 00329 00330 /* Function Body */ 00331 *info = 0; 00332 nofact = lsame_(fact, "N"); 00333 equil = lsame_(fact, "E"); 00334 upper = lsame_(uplo, "U"); 00335 if (nofact || equil) { 00336 *(unsigned char *)equed = 'N'; 00337 rcequ = FALSE_; 00338 } else { 00339 rcequ = lsame_(equed, "Y"); 00340 smlnum = dlamch_("Safe minimum"); 00341 bignum = 1. / smlnum; 00342 } 00343 00344 /* Test the input parameters. */ 00345 00346 if (! nofact && ! equil && ! lsame_(fact, "F")) { 00347 *info = -1; 00348 } else if (! upper && ! lsame_(uplo, "L")) { 00349 *info = -2; 00350 } else if (*n < 0) { 00351 *info = -3; 00352 } else if (*kd < 0) { 00353 *info = -4; 00354 } else if (*nrhs < 0) { 00355 *info = -5; 00356 } else if (*ldab < *kd + 1) { 00357 *info = -7; 00358 } else if (*ldafb < *kd + 1) { 00359 *info = -9; 00360 } else if (lsame_(fact, "F") && ! (rcequ || lsame_( 00361 equed, "N"))) { 00362 *info = -10; 00363 } else { 00364 if (rcequ) { 00365 smin = bignum; 00366 smax = 0.; 00367 i__1 = *n; 00368 for (j = 1; j <= i__1; ++j) { 00369 /* Computing MIN */ 00370 d__1 = smin, d__2 = s[j]; 00371 smin = min(d__1,d__2); 00372 /* Computing MAX */ 00373 d__1 = smax, d__2 = s[j]; 00374 smax = max(d__1,d__2); 00375 /* L10: */ 00376 } 00377 if (smin <= 0.) { 00378 *info = -11; 00379 } else if (*n > 0) { 00380 scond = max(smin,smlnum) / min(smax,bignum); 00381 } else { 00382 scond = 1.; 00383 } 00384 } 00385 if (*info == 0) { 00386 if (*ldb < max(1,*n)) { 00387 *info = -13; 00388 } else if (*ldx < max(1,*n)) { 00389 *info = -15; 00390 } 00391 } 00392 } 00393 00394 if (*info != 0) { 00395 i__1 = -(*info); 00396 xerbla_("ZPBSVX", &i__1); 00397 return 0; 00398 } 00399 00400 if (equil) { 00401 00402 /* Compute row and column scalings to equilibrate the matrix A. */ 00403 00404 zpbequ_(uplo, n, kd, &ab[ab_offset], ldab, &s[1], &scond, &amax, & 00405 infequ); 00406 if (infequ == 0) { 00407 00408 /* Equilibrate the matrix. */ 00409 00410 zlaqhb_(uplo, n, kd, &ab[ab_offset], ldab, &s[1], &scond, &amax, 00411 equed); 00412 rcequ = lsame_(equed, "Y"); 00413 } 00414 } 00415 00416 /* Scale the right-hand side. */ 00417 00418 if (rcequ) { 00419 i__1 = *nrhs; 00420 for (j = 1; j <= i__1; ++j) { 00421 i__2 = *n; 00422 for (i__ = 1; i__ <= i__2; ++i__) { 00423 i__3 = i__ + j * b_dim1; 00424 i__4 = i__; 00425 i__5 = i__ + j * b_dim1; 00426 z__1.r = s[i__4] * b[i__5].r, z__1.i = s[i__4] * b[i__5].i; 00427 b[i__3].r = z__1.r, b[i__3].i = z__1.i; 00428 /* L20: */ 00429 } 00430 /* L30: */ 00431 } 00432 } 00433 00434 if (nofact || equil) { 00435 00436 /* Compute the Cholesky factorization A = U'*U or A = L*L'. */ 00437 00438 if (upper) { 00439 i__1 = *n; 00440 for (j = 1; j <= i__1; ++j) { 00441 /* Computing MAX */ 00442 i__2 = j - *kd; 00443 j1 = max(i__2,1); 00444 i__2 = j - j1 + 1; 00445 zcopy_(&i__2, &ab[*kd + 1 - j + j1 + j * ab_dim1], &c__1, & 00446 afb[*kd + 1 - j + j1 + j * afb_dim1], &c__1); 00447 /* L40: */ 00448 } 00449 } else { 00450 i__1 = *n; 00451 for (j = 1; j <= i__1; ++j) { 00452 /* Computing MIN */ 00453 i__2 = j + *kd; 00454 j2 = min(i__2,*n); 00455 i__2 = j2 - j + 1; 00456 zcopy_(&i__2, &ab[j * ab_dim1 + 1], &c__1, &afb[j * afb_dim1 00457 + 1], &c__1); 00458 /* L50: */ 00459 } 00460 } 00461 00462 zpbtrf_(uplo, n, kd, &afb[afb_offset], ldafb, info); 00463 00464 /* Return if INFO is non-zero. */ 00465 00466 if (*info > 0) { 00467 *rcond = 0.; 00468 return 0; 00469 } 00470 } 00471 00472 /* Compute the norm of the matrix A. */ 00473 00474 anorm = zlanhb_("1", uplo, n, kd, &ab[ab_offset], ldab, &rwork[1]); 00475 00476 /* Compute the reciprocal of the condition number of A. */ 00477 00478 zpbcon_(uplo, n, kd, &afb[afb_offset], ldafb, &anorm, rcond, &work[1], & 00479 rwork[1], info); 00480 00481 /* Compute the solution matrix X. */ 00482 00483 zlacpy_("Full", n, nrhs, &b[b_offset], ldb, &x[x_offset], ldx); 00484 zpbtrs_(uplo, n, kd, nrhs, &afb[afb_offset], ldafb, &x[x_offset], ldx, 00485 info); 00486 00487 /* Use iterative refinement to improve the computed solution and */ 00488 /* compute error bounds and backward error estimates for it. */ 00489 00490 zpbrfs_(uplo, n, kd, nrhs, &ab[ab_offset], ldab, &afb[afb_offset], ldafb, 00491 &b[b_offset], ldb, &x[x_offset], ldx, &ferr[1], &berr[1], &work[1] 00492 , &rwork[1], info); 00493 00494 /* Transform the solution matrix X to a solution of the original */ 00495 /* system. */ 00496 00497 if (rcequ) { 00498 i__1 = *nrhs; 00499 for (j = 1; j <= i__1; ++j) { 00500 i__2 = *n; 00501 for (i__ = 1; i__ <= i__2; ++i__) { 00502 i__3 = i__ + j * x_dim1; 00503 i__4 = i__; 00504 i__5 = i__ + j * x_dim1; 00505 z__1.r = s[i__4] * x[i__5].r, z__1.i = s[i__4] * x[i__5].i; 00506 x[i__3].r = z__1.r, x[i__3].i = z__1.i; 00507 /* L60: */ 00508 } 00509 /* L70: */ 00510 } 00511 i__1 = *nrhs; 00512 for (j = 1; j <= i__1; ++j) { 00513 ferr[j] /= scond; 00514 /* L80: */ 00515 } 00516 } 00517 00518 /* Set INFO = N+1 if the matrix is singular to working precision. */ 00519 00520 if (*rcond < dlamch_("Epsilon")) { 00521 *info = *n + 1; 00522 } 00523 00524 return 0; 00525 00526 /* End of ZPBSVX */ 00527 00528 } /* zpbsvx_ */