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


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