dpteqr.c
Go to the documentation of this file.
00001 /* dpteqr.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 doublereal c_b7 = 0.;
00019 static doublereal c_b8 = 1.;
00020 static integer c__0 = 0;
00021 static integer c__1 = 1;
00022 
00023 /* Subroutine */ int dpteqr_(char *compz, integer *n, doublereal *d__, 
00024         doublereal *e, doublereal *z__, integer *ldz, doublereal *work, 
00025         integer *info)
00026 {
00027     /* System generated locals */
00028     integer z_dim1, z_offset, i__1;
00029 
00030     /* Builtin functions */
00031     double sqrt(doublereal);
00032 
00033     /* Local variables */
00034     doublereal c__[1]   /* was [1][1] */;
00035     integer i__;
00036     doublereal vt[1]    /* was [1][1] */;
00037     integer nru;
00038     extern logical lsame_(char *, char *);
00039     extern /* Subroutine */ int dlaset_(char *, integer *, integer *, 
00040             doublereal *, doublereal *, doublereal *, integer *), 
00041             xerbla_(char *, integer *), dbdsqr_(char *, integer *, 
00042             integer *, integer *, integer *, doublereal *, doublereal *, 
00043             doublereal *, integer *, doublereal *, integer *, doublereal *, 
00044             integer *, doublereal *, integer *);
00045     integer icompz;
00046     extern /* Subroutine */ int dpttrf_(integer *, doublereal *, doublereal *, 
00047              integer *);
00048 
00049 
00050 /*  -- LAPACK routine (version 3.2) -- */
00051 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00052 /*     November 2006 */
00053 
00054 /*     .. Scalar Arguments .. */
00055 /*     .. */
00056 /*     .. Array Arguments .. */
00057 /*     .. */
00058 
00059 /*  Purpose */
00060 /*  ======= */
00061 
00062 /*  DPTEQR computes all eigenvalues and, optionally, eigenvectors of a */
00063 /*  symmetric positive definite tridiagonal matrix by first factoring the */
00064 /*  matrix using DPTTRF, and then calling DBDSQR to compute the singular */
00065 /*  values of the bidiagonal factor. */
00066 
00067 /*  This routine computes the eigenvalues of the positive definite */
00068 /*  tridiagonal matrix to high relative accuracy.  This means that if the */
00069 /*  eigenvalues range over many orders of magnitude in size, then the */
00070 /*  small eigenvalues and corresponding eigenvectors will be computed */
00071 /*  more accurately than, for example, with the standard QR method. */
00072 
00073 /*  The eigenvectors of a full or band symmetric positive definite matrix */
00074 /*  can also be found if DSYTRD, DSPTRD, or DSBTRD has been used to */
00075 /*  reduce this matrix to tridiagonal form. (The reduction to tridiagonal */
00076 /*  form, however, may preclude the possibility of obtaining high */
00077 /*  relative accuracy in the small eigenvalues of the original matrix, if */
00078 /*  these eigenvalues range over many orders of magnitude.) */
00079 
00080 /*  Arguments */
00081 /*  ========= */
00082 
00083 /*  COMPZ   (input) CHARACTER*1 */
00084 /*          = 'N':  Compute eigenvalues only. */
00085 /*          = 'V':  Compute eigenvectors of original symmetric */
00086 /*                  matrix also.  Array Z contains the orthogonal */
00087 /*                  matrix used to reduce the original matrix to */
00088 /*                  tridiagonal form. */
00089 /*          = 'I':  Compute eigenvectors of tridiagonal matrix also. */
00090 
00091 /*  N       (input) INTEGER */
00092 /*          The order of the matrix.  N >= 0. */
00093 
00094 /*  D       (input/output) DOUBLE PRECISION array, dimension (N) */
00095 /*          On entry, the n diagonal elements of the tridiagonal */
00096 /*          matrix. */
00097 /*          On normal exit, D contains the eigenvalues, in descending */
00098 /*          order. */
00099 
00100 /*  E       (input/output) DOUBLE PRECISION array, dimension (N-1) */
00101 /*          On entry, the (n-1) subdiagonal elements of the tridiagonal */
00102 /*          matrix. */
00103 /*          On exit, E has been destroyed. */
00104 
00105 /*  Z       (input/output) DOUBLE PRECISION array, dimension (LDZ, N) */
00106 /*          On entry, if COMPZ = 'V', the orthogonal matrix used in the */
00107 /*          reduction to tridiagonal form. */
00108 /*          On exit, if COMPZ = 'V', the orthonormal eigenvectors of the */
00109 /*          original symmetric matrix; */
00110 /*          if COMPZ = 'I', the orthonormal eigenvectors of the */
00111 /*          tridiagonal matrix. */
00112 /*          If INFO > 0 on exit, Z contains the eigenvectors associated */
00113 /*          with only the stored eigenvalues. */
00114 /*          If  COMPZ = 'N', then Z is not referenced. */
00115 
00116 /*  LDZ     (input) INTEGER */
00117 /*          The leading dimension of the array Z.  LDZ >= 1, and if */
00118 /*          COMPZ = 'V' or 'I', LDZ >= max(1,N). */
00119 
00120 /*  WORK    (workspace) DOUBLE PRECISION array, dimension (4*N) */
00121 
00122 /*  INFO    (output) INTEGER */
00123 /*          = 0:  successful exit. */
00124 /*          < 0:  if INFO = -i, the i-th argument had an illegal value. */
00125 /*          > 0:  if INFO = i, and i is: */
00126 /*                <= N  the Cholesky factorization of the matrix could */
00127 /*                      not be performed because the i-th principal minor */
00128 /*                      was not positive definite. */
00129 /*                > N   the SVD algorithm failed to converge; */
00130 /*                      if INFO = N+i, i off-diagonal elements of the */
00131 /*                      bidiagonal factor did not converge to zero. */
00132 
00133 /*  ===================================================================== */
00134 
00135 /*     .. Parameters .. */
00136 /*     .. */
00137 /*     .. External Functions .. */
00138 /*     .. */
00139 /*     .. External Subroutines .. */
00140 /*     .. */
00141 /*     .. Local Arrays .. */
00142 /*     .. */
00143 /*     .. Local Scalars .. */
00144 /*     .. */
00145 /*     .. Intrinsic Functions .. */
00146 /*     .. */
00147 /*     .. Executable Statements .. */
00148 
00149 /*     Test the input parameters. */
00150 
00151     /* Parameter adjustments */
00152     --d__;
00153     --e;
00154     z_dim1 = *ldz;
00155     z_offset = 1 + z_dim1;
00156     z__ -= z_offset;
00157     --work;
00158 
00159     /* Function Body */
00160     *info = 0;
00161 
00162     if (lsame_(compz, "N")) {
00163         icompz = 0;
00164     } else if (lsame_(compz, "V")) {
00165         icompz = 1;
00166     } else if (lsame_(compz, "I")) {
00167         icompz = 2;
00168     } else {
00169         icompz = -1;
00170     }
00171     if (icompz < 0) {
00172         *info = -1;
00173     } else if (*n < 0) {
00174         *info = -2;
00175     } else if (*ldz < 1 || icompz > 0 && *ldz < max(1,*n)) {
00176         *info = -6;
00177     }
00178     if (*info != 0) {
00179         i__1 = -(*info);
00180         xerbla_("DPTEQR", &i__1);
00181         return 0;
00182     }
00183 
00184 /*     Quick return if possible */
00185 
00186     if (*n == 0) {
00187         return 0;
00188     }
00189 
00190     if (*n == 1) {
00191         if (icompz > 0) {
00192             z__[z_dim1 + 1] = 1.;
00193         }
00194         return 0;
00195     }
00196     if (icompz == 2) {
00197         dlaset_("Full", n, n, &c_b7, &c_b8, &z__[z_offset], ldz);
00198     }
00199 
00200 /*     Call DPTTRF to factor the matrix. */
00201 
00202     dpttrf_(n, &d__[1], &e[1], info);
00203     if (*info != 0) {
00204         return 0;
00205     }
00206     i__1 = *n;
00207     for (i__ = 1; i__ <= i__1; ++i__) {
00208         d__[i__] = sqrt(d__[i__]);
00209 /* L10: */
00210     }
00211     i__1 = *n - 1;
00212     for (i__ = 1; i__ <= i__1; ++i__) {
00213         e[i__] *= d__[i__];
00214 /* L20: */
00215     }
00216 
00217 /*     Call DBDSQR to compute the singular values/vectors of the */
00218 /*     bidiagonal factor. */
00219 
00220     if (icompz > 0) {
00221         nru = *n;
00222     } else {
00223         nru = 0;
00224     }
00225     dbdsqr_("Lower", n, &c__0, &nru, &c__0, &d__[1], &e[1], vt, &c__1, &z__[
00226             z_offset], ldz, c__, &c__1, &work[1], info);
00227 
00228 /*     Square the singular values. */
00229 
00230     if (*info == 0) {
00231         i__1 = *n;
00232         for (i__ = 1; i__ <= i__1; ++i__) {
00233             d__[i__] *= d__[i__];
00234 /* L30: */
00235         }
00236     } else {
00237         *info = *n + *info;
00238     }
00239 
00240     return 0;
00241 
00242 /*     End of DPTEQR */
00243 
00244 } /* dpteqr_ */


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:55:48