00001 /* dposvx.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 /* Subroutine */ int dposvx_(char *fact, char *uplo, integer *n, integer * 00017 nrhs, doublereal *a, integer *lda, doublereal *af, integer *ldaf, 00018 char *equed, doublereal *s, doublereal *b, integer *ldb, doublereal * 00019 x, integer *ldx, doublereal *rcond, doublereal *ferr, doublereal * 00020 berr, doublereal *work, integer *iwork, integer *info) 00021 { 00022 /* System generated locals */ 00023 integer a_dim1, a_offset, af_dim1, af_offset, b_dim1, b_offset, x_dim1, 00024 x_offset, i__1, i__2; 00025 doublereal d__1, d__2; 00026 00027 /* Local variables */ 00028 integer i__, j; 00029 doublereal amax, smin, smax; 00030 extern logical lsame_(char *, char *); 00031 doublereal scond, anorm; 00032 logical equil, rcequ; 00033 extern doublereal dlamch_(char *); 00034 logical nofact; 00035 extern /* Subroutine */ int dlacpy_(char *, integer *, integer *, 00036 doublereal *, integer *, doublereal *, integer *), 00037 xerbla_(char *, integer *); 00038 doublereal bignum; 00039 extern /* Subroutine */ int dpocon_(char *, integer *, doublereal *, 00040 integer *, doublereal *, doublereal *, doublereal *, integer *, 00041 integer *); 00042 integer infequ; 00043 extern doublereal dlansy_(char *, char *, integer *, doublereal *, 00044 integer *, doublereal *); 00045 extern /* Subroutine */ int dlaqsy_(char *, integer *, doublereal *, 00046 integer *, doublereal *, doublereal *, doublereal *, char *), dpoequ_(integer *, doublereal *, integer *, 00047 doublereal *, doublereal *, doublereal *, integer *), dporfs_( 00048 char *, integer *, integer *, doublereal *, integer *, doublereal 00049 *, integer *, doublereal *, integer *, doublereal *, integer *, 00050 doublereal *, doublereal *, doublereal *, integer *, integer *), dpotrf_(char *, integer *, doublereal *, integer *, 00051 integer *); 00052 doublereal smlnum; 00053 extern /* Subroutine */ int dpotrs_(char *, integer *, integer *, 00054 doublereal *, integer *, doublereal *, integer *, integer *); 00055 00056 00057 /* -- LAPACK driver routine (version 3.2) -- */ 00058 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ 00059 /* November 2006 */ 00060 00061 /* .. Scalar Arguments .. */ 00062 /* .. */ 00063 /* .. Array Arguments .. */ 00064 /* .. */ 00065 00066 /* Purpose */ 00067 /* ======= */ 00068 00069 /* DPOSVX uses the Cholesky factorization A = U**T*U or A = L*L**T to */ 00070 /* compute the solution to a real system of linear equations */ 00071 /* A * X = B, */ 00072 /* where A is an N-by-N symmetric positive definite matrix and X and B */ 00073 /* are N-by-NRHS matrices. */ 00074 00075 /* Error bounds on the solution and a condition estimate are also */ 00076 /* provided. */ 00077 00078 /* Description */ 00079 /* =========== */ 00080 00081 /* The following steps are performed: */ 00082 00083 /* 1. If FACT = 'E', real scaling factors are computed to equilibrate */ 00084 /* the system: */ 00085 /* diag(S) * A * diag(S) * inv(diag(S)) * X = diag(S) * B */ 00086 /* Whether or not the system will be equilibrated depends on the */ 00087 /* scaling of the matrix A, but if equilibration is used, A is */ 00088 /* overwritten by diag(S)*A*diag(S) and B by diag(S)*B. */ 00089 00090 /* 2. If FACT = 'N' or 'E', the Cholesky decomposition is used to */ 00091 /* factor the matrix A (after equilibration if FACT = 'E') as */ 00092 /* A = U**T* U, if UPLO = 'U', or */ 00093 /* A = L * L**T, if UPLO = 'L', */ 00094 /* where U is an upper triangular matrix and L is a lower triangular */ 00095 /* matrix. */ 00096 00097 /* 3. If the leading i-by-i principal minor is not positive definite, */ 00098 /* then the routine returns with INFO = i. Otherwise, the factored */ 00099 /* form of A is used to estimate the condition number of the matrix */ 00100 /* A. If the reciprocal of the condition number is less than machine */ 00101 /* precision, INFO = N+1 is returned as a warning, but the routine */ 00102 /* still goes on to solve for X and compute error bounds as */ 00103 /* described below. */ 00104 00105 /* 4. The system of equations is solved for X using the factored form */ 00106 /* of A. */ 00107 00108 /* 5. Iterative refinement is applied to improve the computed solution */ 00109 /* matrix and calculate error bounds and backward error estimates */ 00110 /* for it. */ 00111 00112 /* 6. If equilibration was used, the matrix X is premultiplied by */ 00113 /* diag(S) so that it solves the original system before */ 00114 /* equilibration. */ 00115 00116 /* Arguments */ 00117 /* ========= */ 00118 00119 /* FACT (input) CHARACTER*1 */ 00120 /* Specifies whether or not the factored form of the matrix A is */ 00121 /* supplied on entry, and if not, whether the matrix A should be */ 00122 /* equilibrated before it is factored. */ 00123 /* = 'F': On entry, AF contains the factored form of A. */ 00124 /* If EQUED = 'Y', the matrix A has been equilibrated */ 00125 /* with scaling factors given by S. A and AF will not */ 00126 /* be modified. */ 00127 /* = 'N': The matrix A will be copied to AF and factored. */ 00128 /* = 'E': The matrix A will be equilibrated if necessary, then */ 00129 /* copied to AF and factored. */ 00130 00131 /* UPLO (input) CHARACTER*1 */ 00132 /* = 'U': Upper triangle of A is stored; */ 00133 /* = 'L': Lower triangle of A is stored. */ 00134 00135 /* N (input) INTEGER */ 00136 /* The number of linear equations, i.e., the order of the */ 00137 /* matrix A. N >= 0. */ 00138 00139 /* NRHS (input) INTEGER */ 00140 /* The number of right hand sides, i.e., the number of columns */ 00141 /* of the matrices B and X. NRHS >= 0. */ 00142 00143 /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */ 00144 /* On entry, the symmetric matrix A, except if FACT = 'F' and */ 00145 /* EQUED = 'Y', then A must contain the equilibrated matrix */ 00146 /* diag(S)*A*diag(S). If UPLO = 'U', the leading */ 00147 /* N-by-N upper triangular part of A contains the upper */ 00148 /* triangular part of the matrix A, and the strictly lower */ 00149 /* triangular part of A is not referenced. If UPLO = 'L', the */ 00150 /* leading N-by-N lower triangular part of A contains the lower */ 00151 /* triangular part of the matrix A, and the strictly upper */ 00152 /* triangular part of A is not referenced. A is not modified if */ 00153 /* FACT = 'F' or 'N', or if FACT = 'E' and EQUED = 'N' on exit. */ 00154 00155 /* On exit, if FACT = 'E' and EQUED = 'Y', A is overwritten by */ 00156 /* diag(S)*A*diag(S). */ 00157 00158 /* LDA (input) INTEGER */ 00159 /* The leading dimension of the array A. LDA >= max(1,N). */ 00160 00161 /* AF (input or output) DOUBLE PRECISION array, dimension (LDAF,N) */ 00162 /* If FACT = 'F', then AF is an input argument and on entry */ 00163 /* contains the triangular factor U or L from the Cholesky */ 00164 /* factorization A = U**T*U or A = L*L**T, in the same storage */ 00165 /* format as A. If EQUED .ne. 'N', then AF is the factored form */ 00166 /* of the equilibrated matrix diag(S)*A*diag(S). */ 00167 00168 /* If FACT = 'N', then AF is an output argument and on exit */ 00169 /* returns the triangular factor U or L from the Cholesky */ 00170 /* factorization A = U**T*U or A = L*L**T of the original */ 00171 /* matrix A. */ 00172 00173 /* If FACT = 'E', then AF is an output argument and on exit */ 00174 /* returns the triangular factor U or L from the Cholesky */ 00175 /* factorization A = U**T*U or A = L*L**T of the equilibrated */ 00176 /* matrix A (see the description of A for the form of the */ 00177 /* equilibrated matrix). */ 00178 00179 /* LDAF (input) INTEGER */ 00180 /* The leading dimension of the array AF. LDAF >= max(1,N). */ 00181 00182 /* EQUED (input or output) CHARACTER*1 */ 00183 /* Specifies the form of equilibration that was done. */ 00184 /* = 'N': No equilibration (always true if FACT = 'N'). */ 00185 /* = 'Y': Equilibration was done, i.e., A has been replaced by */ 00186 /* diag(S) * A * diag(S). */ 00187 /* EQUED is an input argument if FACT = 'F'; otherwise, it is an */ 00188 /* output argument. */ 00189 00190 /* S (input or output) DOUBLE PRECISION array, dimension (N) */ 00191 /* The scale factors for A; not accessed if EQUED = 'N'. S is */ 00192 /* an input argument if FACT = 'F'; otherwise, S is an output */ 00193 /* argument. If FACT = 'F' and EQUED = 'Y', each element of S */ 00194 /* must be positive. */ 00195 00196 /* B (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS) */ 00197 /* On entry, the N-by-NRHS right hand side matrix B. */ 00198 /* On exit, if EQUED = 'N', B is not modified; if EQUED = 'Y', */ 00199 /* B is overwritten by diag(S) * B. */ 00200 00201 /* LDB (input) INTEGER */ 00202 /* The leading dimension of the array B. LDB >= max(1,N). */ 00203 00204 /* X (output) DOUBLE PRECISION array, dimension (LDX,NRHS) */ 00205 /* If INFO = 0 or INFO = N+1, the N-by-NRHS solution matrix X to */ 00206 /* the original system of equations. Note that if EQUED = 'Y', */ 00207 /* A and B are modified on exit, and the solution to the */ 00208 /* equilibrated system is inv(diag(S))*X. */ 00209 00210 /* LDX (input) INTEGER */ 00211 /* The leading dimension of the array X. LDX >= max(1,N). */ 00212 00213 /* RCOND (output) DOUBLE PRECISION */ 00214 /* The estimate of the reciprocal condition number of the matrix */ 00215 /* A after equilibration (if done). If RCOND is less than the */ 00216 /* machine precision (in particular, if RCOND = 0), the matrix */ 00217 /* is singular to working precision. This condition is */ 00218 /* indicated by a return code of INFO > 0. */ 00219 00220 /* FERR (output) DOUBLE PRECISION array, dimension (NRHS) */ 00221 /* The estimated forward error bound for each solution vector */ 00222 /* X(j) (the j-th column of the solution matrix X). */ 00223 /* If XTRUE is the true solution corresponding to X(j), FERR(j) */ 00224 /* is an estimated upper bound for the magnitude of the largest */ 00225 /* element in (X(j) - XTRUE) divided by the magnitude of the */ 00226 /* largest element in X(j). The estimate is as reliable as */ 00227 /* the estimate for RCOND, and is almost always a slight */ 00228 /* overestimate of the true error. */ 00229 00230 /* BERR (output) DOUBLE PRECISION array, dimension (NRHS) */ 00231 /* The componentwise relative backward error of each solution */ 00232 /* vector X(j) (i.e., the smallest relative change in */ 00233 /* any element of A or B that makes X(j) an exact solution). */ 00234 00235 /* WORK (workspace) DOUBLE PRECISION array, dimension (3*N) */ 00236 00237 /* IWORK (workspace) INTEGER array, dimension (N) */ 00238 00239 /* INFO (output) INTEGER */ 00240 /* = 0: successful exit */ 00241 /* < 0: if INFO = -i, the i-th argument had an illegal value */ 00242 /* > 0: if INFO = i, and i is */ 00243 /* <= N: the leading minor of order i of A is */ 00244 /* not positive definite, so the factorization */ 00245 /* could not be completed, and the solution has not */ 00246 /* been computed. RCOND = 0 is returned. */ 00247 /* = N+1: U is nonsingular, but RCOND is less than machine */ 00248 /* precision, meaning that the matrix is singular */ 00249 /* to working precision. Nevertheless, the */ 00250 /* solution and error bounds are computed because */ 00251 /* there are a number of situations where the */ 00252 /* computed solution can be more accurate than the */ 00253 /* value of RCOND would suggest. */ 00254 00255 /* ===================================================================== */ 00256 00257 /* .. Parameters .. */ 00258 /* .. */ 00259 /* .. Local Scalars .. */ 00260 /* .. */ 00261 /* .. External Functions .. */ 00262 /* .. */ 00263 /* .. External Subroutines .. */ 00264 /* .. */ 00265 /* .. Intrinsic Functions .. */ 00266 /* .. */ 00267 /* .. Executable Statements .. */ 00268 00269 /* Parameter adjustments */ 00270 a_dim1 = *lda; 00271 a_offset = 1 + a_dim1; 00272 a -= a_offset; 00273 af_dim1 = *ldaf; 00274 af_offset = 1 + af_dim1; 00275 af -= af_offset; 00276 --s; 00277 b_dim1 = *ldb; 00278 b_offset = 1 + b_dim1; 00279 b -= b_offset; 00280 x_dim1 = *ldx; 00281 x_offset = 1 + x_dim1; 00282 x -= x_offset; 00283 --ferr; 00284 --berr; 00285 --work; 00286 --iwork; 00287 00288 /* Function Body */ 00289 *info = 0; 00290 nofact = lsame_(fact, "N"); 00291 equil = lsame_(fact, "E"); 00292 if (nofact || equil) { 00293 *(unsigned char *)equed = 'N'; 00294 rcequ = FALSE_; 00295 } else { 00296 rcequ = lsame_(equed, "Y"); 00297 smlnum = dlamch_("Safe minimum"); 00298 bignum = 1. / smlnum; 00299 } 00300 00301 /* Test the input parameters. */ 00302 00303 if (! nofact && ! equil && ! lsame_(fact, "F")) { 00304 *info = -1; 00305 } else if (! lsame_(uplo, "U") && ! lsame_(uplo, 00306 "L")) { 00307 *info = -2; 00308 } else if (*n < 0) { 00309 *info = -3; 00310 } else if (*nrhs < 0) { 00311 *info = -4; 00312 } else if (*lda < max(1,*n)) { 00313 *info = -6; 00314 } else if (*ldaf < max(1,*n)) { 00315 *info = -8; 00316 } else if (lsame_(fact, "F") && ! (rcequ || lsame_( 00317 equed, "N"))) { 00318 *info = -9; 00319 } else { 00320 if (rcequ) { 00321 smin = bignum; 00322 smax = 0.; 00323 i__1 = *n; 00324 for (j = 1; j <= i__1; ++j) { 00325 /* Computing MIN */ 00326 d__1 = smin, d__2 = s[j]; 00327 smin = min(d__1,d__2); 00328 /* Computing MAX */ 00329 d__1 = smax, d__2 = s[j]; 00330 smax = max(d__1,d__2); 00331 /* L10: */ 00332 } 00333 if (smin <= 0.) { 00334 *info = -10; 00335 } else if (*n > 0) { 00336 scond = max(smin,smlnum) / min(smax,bignum); 00337 } else { 00338 scond = 1.; 00339 } 00340 } 00341 if (*info == 0) { 00342 if (*ldb < max(1,*n)) { 00343 *info = -12; 00344 } else if (*ldx < max(1,*n)) { 00345 *info = -14; 00346 } 00347 } 00348 } 00349 00350 if (*info != 0) { 00351 i__1 = -(*info); 00352 xerbla_("DPOSVX", &i__1); 00353 return 0; 00354 } 00355 00356 if (equil) { 00357 00358 /* Compute row and column scalings to equilibrate the matrix A. */ 00359 00360 dpoequ_(n, &a[a_offset], lda, &s[1], &scond, &amax, &infequ); 00361 if (infequ == 0) { 00362 00363 /* Equilibrate the matrix. */ 00364 00365 dlaqsy_(uplo, n, &a[a_offset], lda, &s[1], &scond, &amax, equed); 00366 rcequ = lsame_(equed, "Y"); 00367 } 00368 } 00369 00370 /* Scale the right hand side. */ 00371 00372 if (rcequ) { 00373 i__1 = *nrhs; 00374 for (j = 1; j <= i__1; ++j) { 00375 i__2 = *n; 00376 for (i__ = 1; i__ <= i__2; ++i__) { 00377 b[i__ + j * b_dim1] = s[i__] * b[i__ + j * b_dim1]; 00378 /* L20: */ 00379 } 00380 /* L30: */ 00381 } 00382 } 00383 00384 if (nofact || equil) { 00385 00386 /* Compute the Cholesky factorization A = U'*U or A = L*L'. */ 00387 00388 dlacpy_(uplo, n, n, &a[a_offset], lda, &af[af_offset], ldaf); 00389 dpotrf_(uplo, n, &af[af_offset], ldaf, info); 00390 00391 /* Return if INFO is non-zero. */ 00392 00393 if (*info > 0) { 00394 *rcond = 0.; 00395 return 0; 00396 } 00397 } 00398 00399 /* Compute the norm of the matrix A. */ 00400 00401 anorm = dlansy_("1", uplo, n, &a[a_offset], lda, &work[1]); 00402 00403 /* Compute the reciprocal of the condition number of A. */ 00404 00405 dpocon_(uplo, n, &af[af_offset], ldaf, &anorm, rcond, &work[1], &iwork[1], 00406 info); 00407 00408 /* Compute the solution matrix X. */ 00409 00410 dlacpy_("Full", n, nrhs, &b[b_offset], ldb, &x[x_offset], ldx); 00411 dpotrs_(uplo, n, nrhs, &af[af_offset], ldaf, &x[x_offset], ldx, info); 00412 00413 /* Use iterative refinement to improve the computed solution and */ 00414 /* compute error bounds and backward error estimates for it. */ 00415 00416 dporfs_(uplo, n, nrhs, &a[a_offset], lda, &af[af_offset], ldaf, &b[ 00417 b_offset], ldb, &x[x_offset], ldx, &ferr[1], &berr[1], &work[1], & 00418 iwork[1], info); 00419 00420 /* Transform the solution matrix X to a solution of the original */ 00421 /* system. */ 00422 00423 if (rcequ) { 00424 i__1 = *nrhs; 00425 for (j = 1; j <= i__1; ++j) { 00426 i__2 = *n; 00427 for (i__ = 1; i__ <= i__2; ++i__) { 00428 x[i__ + j * x_dim1] = s[i__] * x[i__ + j * x_dim1]; 00429 /* L40: */ 00430 } 00431 /* L50: */ 00432 } 00433 i__1 = *nrhs; 00434 for (j = 1; j <= i__1; ++j) { 00435 ferr[j] /= scond; 00436 /* L60: */ 00437 } 00438 } 00439 00440 /* Set INFO = N+1 if the matrix is singular to working precision. */ 00441 00442 if (*rcond < dlamch_("Epsilon")) { 00443 *info = *n + 1; 00444 } 00445 00446 return 0; 00447 00448 /* End of DPOSVX */ 00449 00450 } /* dposvx_ */