00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015
00016
00017
00018 static integer c__1 = 1;
00019
00020 int dsyequb_(char *uplo, integer *n, doublereal *a, integer *
00021 lda, doublereal *s, doublereal *scond, doublereal *amax, doublereal *
00022 work, integer *info)
00023 {
00024
00025 integer a_dim1, a_offset, i__1, i__2;
00026 doublereal d__1, d__2, d__3;
00027
00028
00029 double sqrt(doublereal), log(doublereal), pow_di(doublereal *, integer *);
00030
00031
00032 doublereal d__;
00033 integer i__, j;
00034 doublereal t, u, c0, c1, c2, si;
00035 logical up;
00036 doublereal avg, std, tol, base;
00037 integer iter;
00038 doublereal smin, smax, scale;
00039 extern logical lsame_(char *, char *);
00040 doublereal sumsq;
00041 extern doublereal dlamch_(char *);
00042 extern int xerbla_(char *, integer *);
00043 doublereal bignum;
00044 extern int dlassq_(integer *, doublereal *, integer *,
00045 doublereal *, doublereal *);
00046 doublereal smlnum;
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129 a_dim1 = *lda;
00130 a_offset = 1 + a_dim1;
00131 a -= a_offset;
00132 --s;
00133 --work;
00134
00135
00136 *info = 0;
00137 if (! (lsame_(uplo, "U") || lsame_(uplo, "L"))) {
00138 *info = -1;
00139 } else if (*n < 0) {
00140 *info = -2;
00141 } else if (*lda < max(1,*n)) {
00142 *info = -4;
00143 }
00144 if (*info != 0) {
00145 i__1 = -(*info);
00146 xerbla_("DSYEQUB", &i__1);
00147 return 0;
00148 }
00149 up = lsame_(uplo, "U");
00150 *amax = 0.;
00151
00152
00153
00154 if (*n == 0) {
00155 *scond = 1.;
00156 return 0;
00157 }
00158 i__1 = *n;
00159 for (i__ = 1; i__ <= i__1; ++i__) {
00160 s[i__] = 0.;
00161 }
00162 *amax = 0.;
00163 if (up) {
00164 i__1 = *n;
00165 for (j = 1; j <= i__1; ++j) {
00166 i__2 = j - 1;
00167 for (i__ = 1; i__ <= i__2; ++i__) {
00168
00169 d__2 = s[i__], d__3 = (d__1 = a[i__ + j * a_dim1], abs(d__1));
00170 s[i__] = max(d__2,d__3);
00171
00172 d__2 = s[j], d__3 = (d__1 = a[i__ + j * a_dim1], abs(d__1));
00173 s[j] = max(d__2,d__3);
00174
00175 d__2 = *amax, d__3 = (d__1 = a[i__ + j * a_dim1], abs(d__1));
00176 *amax = max(d__2,d__3);
00177 }
00178
00179 d__2 = s[j], d__3 = (d__1 = a[j + j * a_dim1], abs(d__1));
00180 s[j] = max(d__2,d__3);
00181
00182 d__2 = *amax, d__3 = (d__1 = a[j + j * a_dim1], abs(d__1));
00183 *amax = max(d__2,d__3);
00184 }
00185 } else {
00186 i__1 = *n;
00187 for (j = 1; j <= i__1; ++j) {
00188
00189 d__2 = s[j], d__3 = (d__1 = a[j + j * a_dim1], abs(d__1));
00190 s[j] = max(d__2,d__3);
00191
00192 d__2 = *amax, d__3 = (d__1 = a[j + j * a_dim1], abs(d__1));
00193 *amax = max(d__2,d__3);
00194 i__2 = *n;
00195 for (i__ = j + 1; i__ <= i__2; ++i__) {
00196
00197 d__2 = s[i__], d__3 = (d__1 = a[i__ + j * a_dim1], abs(d__1));
00198 s[i__] = max(d__2,d__3);
00199
00200 d__2 = s[j], d__3 = (d__1 = a[i__ + j * a_dim1], abs(d__1));
00201 s[j] = max(d__2,d__3);
00202
00203 d__2 = *amax, d__3 = (d__1 = a[i__ + j * a_dim1], abs(d__1));
00204 *amax = max(d__2,d__3);
00205 }
00206 }
00207 }
00208 i__1 = *n;
00209 for (j = 1; j <= i__1; ++j) {
00210 s[j] = 1. / s[j];
00211 }
00212 tol = 1. / sqrt(*n * 2.);
00213 for (iter = 1; iter <= 100; ++iter) {
00214 scale = 0.;
00215 sumsq = 0.;
00216
00217 i__1 = *n;
00218 for (i__ = 1; i__ <= i__1; ++i__) {
00219 work[i__] = 0.;
00220 }
00221 if (up) {
00222 i__1 = *n;
00223 for (j = 1; j <= i__1; ++j) {
00224 i__2 = j - 1;
00225 for (i__ = 1; i__ <= i__2; ++i__) {
00226 t = (d__1 = a[i__ + j * a_dim1], abs(d__1));
00227 work[i__] += (d__1 = a[i__ + j * a_dim1], abs(d__1)) * s[
00228 j];
00229 work[j] += (d__1 = a[i__ + j * a_dim1], abs(d__1)) * s[
00230 i__];
00231 }
00232 work[j] += (d__1 = a[j + j * a_dim1], abs(d__1)) * s[j];
00233 }
00234 } else {
00235 i__1 = *n;
00236 for (j = 1; j <= i__1; ++j) {
00237 work[j] += (d__1 = a[j + j * a_dim1], abs(d__1)) * s[j];
00238 i__2 = *n;
00239 for (i__ = j + 1; i__ <= i__2; ++i__) {
00240 t = (d__1 = a[i__ + j * a_dim1], abs(d__1));
00241 work[i__] += (d__1 = a[i__ + j * a_dim1], abs(d__1)) * s[
00242 j];
00243 work[j] += (d__1 = a[i__ + j * a_dim1], abs(d__1)) * s[
00244 i__];
00245 }
00246 }
00247 }
00248
00249 avg = 0.;
00250 i__1 = *n;
00251 for (i__ = 1; i__ <= i__1; ++i__) {
00252 avg += s[i__] * work[i__];
00253 }
00254 avg /= *n;
00255 std = 0.;
00256 i__1 = *n * 3;
00257 for (i__ = (*n << 1) + 1; i__ <= i__1; ++i__) {
00258 work[i__] = s[i__ - (*n << 1)] * work[i__ - (*n << 1)] - avg;
00259 }
00260 dlassq_(n, &work[(*n << 1) + 1], &c__1, &scale, &sumsq);
00261 std = scale * sqrt(sumsq / *n);
00262 if (std < tol * avg) {
00263 goto L999;
00264 }
00265 i__1 = *n;
00266 for (i__ = 1; i__ <= i__1; ++i__) {
00267 t = (d__1 = a[i__ + i__ * a_dim1], abs(d__1));
00268 si = s[i__];
00269 c2 = (*n - 1) * t;
00270 c1 = (*n - 2) * (work[i__] - t * si);
00271 c0 = -(t * si) * si + work[i__] * 2 * si - *n * avg;
00272 d__ = c1 * c1 - c0 * 4 * c2;
00273 if (d__ <= 0.) {
00274 *info = -1;
00275 return 0;
00276 }
00277 si = c0 * -2 / (c1 + sqrt(d__));
00278 d__ = si - s[i__];
00279 u = 0.;
00280 if (up) {
00281 i__2 = i__;
00282 for (j = 1; j <= i__2; ++j) {
00283 t = (d__1 = a[j + i__ * a_dim1], abs(d__1));
00284 u += s[j] * t;
00285 work[j] += d__ * t;
00286 }
00287 i__2 = *n;
00288 for (j = i__ + 1; j <= i__2; ++j) {
00289 t = (d__1 = a[i__ + j * a_dim1], abs(d__1));
00290 u += s[j] * t;
00291 work[j] += d__ * t;
00292 }
00293 } else {
00294 i__2 = i__;
00295 for (j = 1; j <= i__2; ++j) {
00296 t = (d__1 = a[i__ + j * a_dim1], abs(d__1));
00297 u += s[j] * t;
00298 work[j] += d__ * t;
00299 }
00300 i__2 = *n;
00301 for (j = i__ + 1; j <= i__2; ++j) {
00302 t = (d__1 = a[j + i__ * a_dim1], abs(d__1));
00303 u += s[j] * t;
00304 work[j] += d__ * t;
00305 }
00306 }
00307 avg += (u + work[i__]) * d__ / *n;
00308 s[i__] = si;
00309 }
00310 }
00311 L999:
00312 smlnum = dlamch_("SAFEMIN");
00313 bignum = 1. / smlnum;
00314 smin = bignum;
00315 smax = 0.;
00316 t = 1. / sqrt(avg);
00317 base = dlamch_("B");
00318 u = 1. / log(base);
00319 i__1 = *n;
00320 for (i__ = 1; i__ <= i__1; ++i__) {
00321 i__2 = (integer) (u * log(s[i__] * t));
00322 s[i__] = pow_di(&base, &i__2);
00323
00324 d__1 = smin, d__2 = s[i__];
00325 smin = min(d__1,d__2);
00326
00327 d__1 = smax, d__2 = s[i__];
00328 smax = max(d__1,d__2);
00329 }
00330 *scond = max(smin,smlnum) / min(smax,bignum);
00331
00332 return 0;
00333 }