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


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:56:43