00001 /* spteqr.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 real c_b7 = 0.f; 00019 static real c_b8 = 1.f; 00020 static integer c__0 = 0; 00021 static integer c__1 = 1; 00022 00023 /* Subroutine */ int spteqr_(char *compz, integer *n, real *d__, real *e, 00024 real *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 real c__[1] /* was [1][1] */; 00034 integer i__; 00035 real vt[1] /* was [1][1] */; 00036 integer nru; 00037 extern logical lsame_(char *, char *); 00038 extern /* Subroutine */ int xerbla_(char *, integer *), slaset_( 00039 char *, integer *, integer *, real *, real *, real *, integer *), sbdsqr_(char *, integer *, integer *, integer *, integer 00040 *, real *, real *, real *, integer *, real *, integer *, real *, 00041 integer *, real *, integer *); 00042 integer icompz; 00043 extern /* Subroutine */ int spttrf_(integer *, real *, real *, integer *); 00044 00045 00046 /* -- LAPACK routine (version 3.2) -- */ 00047 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ 00048 /* November 2006 */ 00049 00050 /* .. Scalar Arguments .. */ 00051 /* .. */ 00052 /* .. Array Arguments .. */ 00053 /* .. */ 00054 00055 /* Purpose */ 00056 /* ======= */ 00057 00058 /* SPTEQR computes all eigenvalues and, optionally, eigenvectors of a */ 00059 /* symmetric positive definite tridiagonal matrix by first factoring the */ 00060 /* matrix using SPTTRF, and then calling SBDSQR to compute the singular */ 00061 /* values of the bidiagonal factor. */ 00062 00063 /* This routine computes the eigenvalues of the positive definite */ 00064 /* tridiagonal matrix to high relative accuracy. This means that if the */ 00065 /* eigenvalues range over many orders of magnitude in size, then the */ 00066 /* small eigenvalues and corresponding eigenvectors will be computed */ 00067 /* more accurately than, for example, with the standard QR method. */ 00068 00069 /* The eigenvectors of a full or band symmetric positive definite matrix */ 00070 /* can also be found if SSYTRD, SSPTRD, or SSBTRD has been used to */ 00071 /* reduce this matrix to tridiagonal form. (The reduction to tridiagonal */ 00072 /* form, however, may preclude the possibility of obtaining high */ 00073 /* relative accuracy in the small eigenvalues of the original matrix, if */ 00074 /* these eigenvalues range over many orders of magnitude.) */ 00075 00076 /* Arguments */ 00077 /* ========= */ 00078 00079 /* COMPZ (input) CHARACTER*1 */ 00080 /* = 'N': Compute eigenvalues only. */ 00081 /* = 'V': Compute eigenvectors of original symmetric */ 00082 /* matrix also. Array Z contains the orthogonal */ 00083 /* matrix used to reduce the original matrix to */ 00084 /* tridiagonal form. */ 00085 /* = 'I': Compute eigenvectors of tridiagonal matrix also. */ 00086 00087 /* N (input) INTEGER */ 00088 /* The order of the matrix. N >= 0. */ 00089 00090 /* D (input/output) REAL array, dimension (N) */ 00091 /* On entry, the n diagonal elements of the tridiagonal */ 00092 /* 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) REAL array, dimension (LDZ, N) */ 00102 /* On entry, if COMPZ = 'V', the orthogonal matrix used in the */ 00103 /* reduction to tridiagonal form. */ 00104 /* On exit, if COMPZ = 'V', the orthonormal eigenvectors of the */ 00105 /* original symmetric 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_("SPTEQR", &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 z__[z_dim1 + 1] = 1.f; 00189 } 00190 return 0; 00191 } 00192 if (icompz == 2) { 00193 slaset_("Full", n, n, &c_b7, &c_b8, &z__[z_offset], ldz); 00194 } 00195 00196 /* Call SPTTRF to factor the matrix. */ 00197 00198 spttrf_(n, &d__[1], &e[1], info); 00199 if (*info != 0) { 00200 return 0; 00201 } 00202 i__1 = *n; 00203 for (i__ = 1; i__ <= i__1; ++i__) { 00204 d__[i__] = sqrt(d__[i__]); 00205 /* L10: */ 00206 } 00207 i__1 = *n - 1; 00208 for (i__ = 1; i__ <= i__1; ++i__) { 00209 e[i__] *= d__[i__]; 00210 /* L20: */ 00211 } 00212 00213 /* Call SBDSQR to compute the singular values/vectors of the */ 00214 /* bidiagonal factor. */ 00215 00216 if (icompz > 0) { 00217 nru = *n; 00218 } else { 00219 nru = 0; 00220 } 00221 sbdsqr_("Lower", n, &c__0, &nru, &c__0, &d__[1], &e[1], vt, &c__1, &z__[ 00222 z_offset], ldz, c__, &c__1, &work[1], info); 00223 00224 /* Square the singular values. */ 00225 00226 if (*info == 0) { 00227 i__1 = *n; 00228 for (i__ = 1; i__ <= i__1; ++i__) { 00229 d__[i__] *= d__[i__]; 00230 /* L30: */ 00231 } 00232 } else { 00233 *info = *n + *info; 00234 } 00235 00236 return 0; 00237 00238 /* End of SPTEQR */ 00239 00240 } /* spteqr_ */