00001 /* slagtf.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 slagtf_(integer *n, real *a, real *lambda, real *b, real 00017 *c__, real *tol, real *d__, integer *in, integer *info) 00018 { 00019 /* System generated locals */ 00020 integer i__1; 00021 real r__1, r__2; 00022 00023 /* Local variables */ 00024 integer k; 00025 real tl, eps, piv1, piv2, temp, mult, scale1, scale2; 00026 extern doublereal slamch_(char *); 00027 extern /* Subroutine */ int xerbla_(char *, integer *); 00028 00029 00030 /* -- LAPACK routine (version 3.2) -- */ 00031 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ 00032 /* November 2006 */ 00033 00034 /* .. Scalar Arguments .. */ 00035 /* .. */ 00036 /* .. Array Arguments .. */ 00037 /* .. */ 00038 00039 /* Purpose */ 00040 /* ======= */ 00041 00042 /* SLAGTF factorizes the matrix (T - lambda*I), where T is an n by n */ 00043 /* tridiagonal matrix and lambda is a scalar, as */ 00044 00045 /* T - lambda*I = PLU, */ 00046 00047 /* where P is a permutation matrix, L is a unit lower tridiagonal matrix */ 00048 /* with at most one non-zero sub-diagonal elements per column and U is */ 00049 /* an upper triangular matrix with at most two non-zero super-diagonal */ 00050 /* elements per column. */ 00051 00052 /* The factorization is obtained by Gaussian elimination with partial */ 00053 /* pivoting and implicit row scaling. */ 00054 00055 /* The parameter LAMBDA is included in the routine so that SLAGTF may */ 00056 /* be used, in conjunction with SLAGTS, to obtain eigenvectors of T by */ 00057 /* inverse iteration. */ 00058 00059 /* Arguments */ 00060 /* ========= */ 00061 00062 /* N (input) INTEGER */ 00063 /* The order of the matrix T. */ 00064 00065 /* A (input/output) REAL array, dimension (N) */ 00066 /* On entry, A must contain the diagonal elements of T. */ 00067 00068 /* On exit, A is overwritten by the n diagonal elements of the */ 00069 /* upper triangular matrix U of the factorization of T. */ 00070 00071 /* LAMBDA (input) REAL */ 00072 /* On entry, the scalar lambda. */ 00073 00074 /* B (input/output) REAL array, dimension (N-1) */ 00075 /* On entry, B must contain the (n-1) super-diagonal elements of */ 00076 /* T. */ 00077 00078 /* On exit, B is overwritten by the (n-1) super-diagonal */ 00079 /* elements of the matrix U of the factorization of T. */ 00080 00081 /* C (input/output) REAL array, dimension (N-1) */ 00082 /* On entry, C must contain the (n-1) sub-diagonal elements of */ 00083 /* T. */ 00084 00085 /* On exit, C is overwritten by the (n-1) sub-diagonal elements */ 00086 /* of the matrix L of the factorization of T. */ 00087 00088 /* TOL (input) REAL */ 00089 /* On entry, a relative tolerance used to indicate whether or */ 00090 /* not the matrix (T - lambda*I) is nearly singular. TOL should */ 00091 /* normally be chose as approximately the largest relative error */ 00092 /* in the elements of T. For example, if the elements of T are */ 00093 /* correct to about 4 significant figures, then TOL should be */ 00094 /* set to about 5*10**(-4). If TOL is supplied as less than eps, */ 00095 /* where eps is the relative machine precision, then the value */ 00096 /* eps is used in place of TOL. */ 00097 00098 /* D (output) REAL array, dimension (N-2) */ 00099 /* On exit, D is overwritten by the (n-2) second super-diagonal */ 00100 /* elements of the matrix U of the factorization of T. */ 00101 00102 /* IN (output) INTEGER array, dimension (N) */ 00103 /* On exit, IN contains details of the permutation matrix P. If */ 00104 /* an interchange occurred at the kth step of the elimination, */ 00105 /* then IN(k) = 1, otherwise IN(k) = 0. The element IN(n) */ 00106 /* returns the smallest positive integer j such that */ 00107 00108 /* abs( u(j,j) ).le. norm( (T - lambda*I)(j) )*TOL, */ 00109 00110 /* where norm( A(j) ) denotes the sum of the absolute values of */ 00111 /* the jth row of the matrix A. If no such j exists then IN(n) */ 00112 /* is returned as zero. If IN(n) is returned as positive, then a */ 00113 /* diagonal element of U is small, indicating that */ 00114 /* (T - lambda*I) is singular or nearly singular, */ 00115 00116 /* INFO (output) INTEGER */ 00117 /* = 0 : successful exit */ 00118 /* .lt. 0: if INFO = -k, the kth argument had an illegal value */ 00119 00120 /* ===================================================================== */ 00121 00122 /* .. Parameters .. */ 00123 /* .. */ 00124 /* .. Local Scalars .. */ 00125 /* .. */ 00126 /* .. Intrinsic Functions .. */ 00127 /* .. */ 00128 /* .. External Functions .. */ 00129 /* .. */ 00130 /* .. External Subroutines .. */ 00131 /* .. */ 00132 /* .. Executable Statements .. */ 00133 00134 /* Parameter adjustments */ 00135 --in; 00136 --d__; 00137 --c__; 00138 --b; 00139 --a; 00140 00141 /* Function Body */ 00142 *info = 0; 00143 if (*n < 0) { 00144 *info = -1; 00145 i__1 = -(*info); 00146 xerbla_("SLAGTF", &i__1); 00147 return 0; 00148 } 00149 00150 if (*n == 0) { 00151 return 0; 00152 } 00153 00154 a[1] -= *lambda; 00155 in[*n] = 0; 00156 if (*n == 1) { 00157 if (a[1] == 0.f) { 00158 in[1] = 1; 00159 } 00160 return 0; 00161 } 00162 00163 eps = slamch_("Epsilon"); 00164 00165 tl = dmax(*tol,eps); 00166 scale1 = dabs(a[1]) + dabs(b[1]); 00167 i__1 = *n - 1; 00168 for (k = 1; k <= i__1; ++k) { 00169 a[k + 1] -= *lambda; 00170 scale2 = (r__1 = c__[k], dabs(r__1)) + (r__2 = a[k + 1], dabs(r__2)); 00171 if (k < *n - 1) { 00172 scale2 += (r__1 = b[k + 1], dabs(r__1)); 00173 } 00174 if (a[k] == 0.f) { 00175 piv1 = 0.f; 00176 } else { 00177 piv1 = (r__1 = a[k], dabs(r__1)) / scale1; 00178 } 00179 if (c__[k] == 0.f) { 00180 in[k] = 0; 00181 piv2 = 0.f; 00182 scale1 = scale2; 00183 if (k < *n - 1) { 00184 d__[k] = 0.f; 00185 } 00186 } else { 00187 piv2 = (r__1 = c__[k], dabs(r__1)) / scale2; 00188 if (piv2 <= piv1) { 00189 in[k] = 0; 00190 scale1 = scale2; 00191 c__[k] /= a[k]; 00192 a[k + 1] -= c__[k] * b[k]; 00193 if (k < *n - 1) { 00194 d__[k] = 0.f; 00195 } 00196 } else { 00197 in[k] = 1; 00198 mult = a[k] / c__[k]; 00199 a[k] = c__[k]; 00200 temp = a[k + 1]; 00201 a[k + 1] = b[k] - mult * temp; 00202 if (k < *n - 1) { 00203 d__[k] = b[k + 1]; 00204 b[k + 1] = -mult * d__[k]; 00205 } 00206 b[k] = temp; 00207 c__[k] = mult; 00208 } 00209 } 00210 if (dmax(piv1,piv2) <= tl && in[*n] == 0) { 00211 in[*n] = k; 00212 } 00213 /* L10: */ 00214 } 00215 if ((r__1 = a[*n], dabs(r__1)) <= scale1 * tl && in[*n] == 0) { 00216 in[*n] = *n; 00217 } 00218 00219 return 0; 00220 00221 /* End of SLAGTF */ 00222 00223 } /* slagtf_ */