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 zsyequb_(char *uplo, integer *n, doublecomplex *a,
00021 integer *lda, doublereal *s, doublereal *scond, doublereal *amax,
00022 doublecomplex *work, integer *info)
00023 {
00024
00025 integer a_dim1, a_offset, i__1, i__2, i__3, i__4, i__5;
00026 doublereal d__1, d__2, d__3, d__4;
00027 doublecomplex z__1, z__2, z__3, z__4;
00028
00029
00030 double d_imag(doublecomplex *), sqrt(doublereal), log(doublereal), pow_di(
00031 doublereal *, integer *);
00032
00033
00034 doublereal d__;
00035 integer i__, j;
00036 doublereal t, u, c0, c1, c2, si;
00037 logical up;
00038 doublereal avg, std, tol, base;
00039 integer iter;
00040 doublereal smin, smax, scale;
00041 extern logical lsame_(char *, char *);
00042 doublereal sumsq;
00043 extern doublereal dlamch_(char *);
00044 extern int xerbla_(char *, integer *);
00045 doublereal bignum, smlnum;
00046 extern int zlassq_(integer *, doublecomplex *, integer *,
00047 doublereal *, doublereal *);
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
00130
00131
00132
00133
00134 a_dim1 = *lda;
00135 a_offset = 1 + a_dim1;
00136 a -= a_offset;
00137 --s;
00138 --work;
00139
00140
00141 *info = 0;
00142 if (! (lsame_(uplo, "U") || lsame_(uplo, "L"))) {
00143 *info = -1;
00144 } else if (*n < 0) {
00145 *info = -2;
00146 } else if (*lda < max(1,*n)) {
00147 *info = -4;
00148 }
00149 if (*info != 0) {
00150 i__1 = -(*info);
00151 xerbla_("ZSYEQUB", &i__1);
00152 return 0;
00153 }
00154 up = lsame_(uplo, "U");
00155 *amax = 0.;
00156
00157
00158
00159 if (*n == 0) {
00160 *scond = 1.;
00161 return 0;
00162 }
00163 i__1 = *n;
00164 for (i__ = 1; i__ <= i__1; ++i__) {
00165 s[i__] = 0.;
00166 }
00167 *amax = 0.;
00168 if (up) {
00169 i__1 = *n;
00170 for (j = 1; j <= i__1; ++j) {
00171 i__2 = j - 1;
00172 for (i__ = 1; i__ <= i__2; ++i__) {
00173
00174 i__3 = i__ + j * a_dim1;
00175 d__3 = s[i__], d__4 = (d__1 = a[i__3].r, abs(d__1)) + (d__2 =
00176 d_imag(&a[i__ + j * a_dim1]), abs(d__2));
00177 s[i__] = max(d__3,d__4);
00178
00179 i__3 = i__ + j * a_dim1;
00180 d__3 = s[j], d__4 = (d__1 = a[i__3].r, abs(d__1)) + (d__2 =
00181 d_imag(&a[i__ + j * a_dim1]), abs(d__2));
00182 s[j] = max(d__3,d__4);
00183
00184 i__3 = i__ + j * a_dim1;
00185 d__3 = *amax, d__4 = (d__1 = a[i__3].r, abs(d__1)) + (d__2 =
00186 d_imag(&a[i__ + j * a_dim1]), abs(d__2));
00187 *amax = max(d__3,d__4);
00188 }
00189
00190 i__2 = j + j * a_dim1;
00191 d__3 = s[j], d__4 = (d__1 = a[i__2].r, abs(d__1)) + (d__2 =
00192 d_imag(&a[j + j * a_dim1]), abs(d__2));
00193 s[j] = max(d__3,d__4);
00194
00195 i__2 = j + j * a_dim1;
00196 d__3 = *amax, d__4 = (d__1 = a[i__2].r, abs(d__1)) + (d__2 =
00197 d_imag(&a[j + j * a_dim1]), abs(d__2));
00198 *amax = max(d__3,d__4);
00199 }
00200 } else {
00201 i__1 = *n;
00202 for (j = 1; j <= i__1; ++j) {
00203
00204 i__2 = j + j * a_dim1;
00205 d__3 = s[j], d__4 = (d__1 = a[i__2].r, abs(d__1)) + (d__2 =
00206 d_imag(&a[j + j * a_dim1]), abs(d__2));
00207 s[j] = max(d__3,d__4);
00208
00209 i__2 = j + j * a_dim1;
00210 d__3 = *amax, d__4 = (d__1 = a[i__2].r, abs(d__1)) + (d__2 =
00211 d_imag(&a[j + j * a_dim1]), abs(d__2));
00212 *amax = max(d__3,d__4);
00213 i__2 = *n;
00214 for (i__ = j + 1; i__ <= i__2; ++i__) {
00215
00216 i__3 = i__ + j * a_dim1;
00217 d__3 = s[i__], d__4 = (d__1 = a[i__3].r, abs(d__1)) + (d__2 =
00218 d_imag(&a[i__ + j * a_dim1]), abs(d__2));
00219 s[i__] = max(d__3,d__4);
00220
00221 i__3 = i__ + j * a_dim1;
00222 d__3 = s[j], d__4 = (d__1 = a[i__3].r, abs(d__1)) + (d__2 =
00223 d_imag(&a[i__ + j * a_dim1]), abs(d__2));
00224 s[j] = max(d__3,d__4);
00225
00226 i__3 = i__ + j * a_dim1;
00227 d__3 = *amax, d__4 = (d__1 = a[i__3].r, abs(d__1)) + (d__2 =
00228 d_imag(&a[i__ + j * a_dim1]), abs(d__2));
00229 *amax = max(d__3,d__4);
00230 }
00231 }
00232 }
00233 i__1 = *n;
00234 for (j = 1; j <= i__1; ++j) {
00235 s[j] = 1. / s[j];
00236 }
00237 tol = 1. / sqrt(*n * 2.);
00238 for (iter = 1; iter <= 100; ++iter) {
00239 scale = 0.;
00240 sumsq = 0.;
00241
00242 i__1 = *n;
00243 for (i__ = 1; i__ <= i__1; ++i__) {
00244 i__2 = i__;
00245 work[i__2].r = 0., work[i__2].i = 0.;
00246 }
00247 if (up) {
00248 i__1 = *n;
00249 for (j = 1; j <= i__1; ++j) {
00250 i__2 = j - 1;
00251 for (i__ = 1; i__ <= i__2; ++i__) {
00252 i__3 = i__ + j * a_dim1;
00253 t = (d__1 = a[i__3].r, abs(d__1)) + (d__2 = d_imag(&a[i__
00254 + j * a_dim1]), abs(d__2));
00255 i__3 = i__;
00256 i__4 = i__;
00257 i__5 = i__ + j * a_dim1;
00258 d__3 = ((d__1 = a[i__5].r, abs(d__1)) + (d__2 = d_imag(&a[
00259 i__ + j * a_dim1]), abs(d__2))) * s[j];
00260 z__1.r = work[i__4].r + d__3, z__1.i = work[i__4].i;
00261 work[i__3].r = z__1.r, work[i__3].i = z__1.i;
00262 i__3 = j;
00263 i__4 = j;
00264 i__5 = i__ + j * a_dim1;
00265 d__3 = ((d__1 = a[i__5].r, abs(d__1)) + (d__2 = d_imag(&a[
00266 i__ + j * a_dim1]), abs(d__2))) * s[i__];
00267 z__1.r = work[i__4].r + d__3, z__1.i = work[i__4].i;
00268 work[i__3].r = z__1.r, work[i__3].i = z__1.i;
00269 }
00270 i__2 = j;
00271 i__3 = j;
00272 i__4 = j + j * a_dim1;
00273 d__3 = ((d__1 = a[i__4].r, abs(d__1)) + (d__2 = d_imag(&a[j +
00274 j * a_dim1]), abs(d__2))) * s[j];
00275 z__1.r = work[i__3].r + d__3, z__1.i = work[i__3].i;
00276 work[i__2].r = z__1.r, work[i__2].i = z__1.i;
00277 }
00278 } else {
00279 i__1 = *n;
00280 for (j = 1; j <= i__1; ++j) {
00281 i__2 = j;
00282 i__3 = j;
00283 i__4 = j + j * a_dim1;
00284 d__3 = ((d__1 = a[i__4].r, abs(d__1)) + (d__2 = d_imag(&a[j +
00285 j * a_dim1]), abs(d__2))) * s[j];
00286 z__1.r = work[i__3].r + d__3, z__1.i = work[i__3].i;
00287 work[i__2].r = z__1.r, work[i__2].i = z__1.i;
00288 i__2 = *n;
00289 for (i__ = j + 1; i__ <= i__2; ++i__) {
00290 i__3 = i__ + j * a_dim1;
00291 t = (d__1 = a[i__3].r, abs(d__1)) + (d__2 = d_imag(&a[i__
00292 + j * a_dim1]), abs(d__2));
00293 i__3 = i__;
00294 i__4 = i__;
00295 i__5 = i__ + j * a_dim1;
00296 d__3 = ((d__1 = a[i__5].r, abs(d__1)) + (d__2 = d_imag(&a[
00297 i__ + j * a_dim1]), abs(d__2))) * s[j];
00298 z__1.r = work[i__4].r + d__3, z__1.i = work[i__4].i;
00299 work[i__3].r = z__1.r, work[i__3].i = z__1.i;
00300 i__3 = j;
00301 i__4 = j;
00302 i__5 = i__ + j * a_dim1;
00303 d__3 = ((d__1 = a[i__5].r, abs(d__1)) + (d__2 = d_imag(&a[
00304 i__ + j * a_dim1]), abs(d__2))) * s[i__];
00305 z__1.r = work[i__4].r + d__3, z__1.i = work[i__4].i;
00306 work[i__3].r = z__1.r, work[i__3].i = z__1.i;
00307 }
00308 }
00309 }
00310
00311 avg = 0.;
00312 i__1 = *n;
00313 for (i__ = 1; i__ <= i__1; ++i__) {
00314 i__2 = i__;
00315 i__3 = i__;
00316 z__2.r = s[i__2] * work[i__3].r, z__2.i = s[i__2] * work[i__3].i;
00317 z__1.r = avg + z__2.r, z__1.i = z__2.i;
00318 avg = z__1.r;
00319 }
00320 avg /= *n;
00321 std = 0.;
00322 i__1 = *n << 1;
00323 for (i__ = *n + 1; i__ <= i__1; ++i__) {
00324 i__2 = i__;
00325 i__3 = i__ - *n;
00326 i__4 = i__ - *n;
00327 z__2.r = s[i__3] * work[i__4].r, z__2.i = s[i__3] * work[i__4].i;
00328 z__1.r = z__2.r - avg, z__1.i = z__2.i;
00329 work[i__2].r = z__1.r, work[i__2].i = z__1.i;
00330 }
00331 zlassq_(n, &work[*n + 1], &c__1, &scale, &sumsq);
00332 std = scale * sqrt(sumsq / *n);
00333 if (std < tol * avg) {
00334 goto L999;
00335 }
00336 i__1 = *n;
00337 for (i__ = 1; i__ <= i__1; ++i__) {
00338 i__2 = i__ + i__ * a_dim1;
00339 t = (d__1 = a[i__2].r, abs(d__1)) + (d__2 = d_imag(&a[i__ + i__ *
00340 a_dim1]), abs(d__2));
00341 si = s[i__];
00342 c2 = (*n - 1) * t;
00343 i__2 = *n - 2;
00344 i__3 = i__;
00345 d__1 = t * si;
00346 z__2.r = work[i__3].r - d__1, z__2.i = work[i__3].i;
00347 d__2 = (doublereal) i__2;
00348 z__1.r = d__2 * z__2.r, z__1.i = d__2 * z__2.i;
00349 c1 = z__1.r;
00350 d__1 = -(t * si) * si;
00351 i__2 = i__;
00352 d__2 = 2.;
00353 z__4.r = d__2 * work[i__2].r, z__4.i = d__2 * work[i__2].i;
00354 z__3.r = si * z__4.r, z__3.i = si * z__4.i;
00355 z__2.r = d__1 + z__3.r, z__2.i = z__3.i;
00356 d__3 = *n * avg;
00357 z__1.r = z__2.r - d__3, z__1.i = z__2.i;
00358 c0 = z__1.r;
00359 d__ = c1 * c1 - c0 * 4 * c2;
00360 if (d__ <= 0.) {
00361 *info = -1;
00362 return 0;
00363 }
00364 si = c0 * -2 / (c1 + sqrt(d__));
00365 d__ = si - s[i__];
00366 u = 0.;
00367 if (up) {
00368 i__2 = i__;
00369 for (j = 1; j <= i__2; ++j) {
00370 i__3 = j + i__ * a_dim1;
00371 t = (d__1 = a[i__3].r, abs(d__1)) + (d__2 = d_imag(&a[j +
00372 i__ * a_dim1]), abs(d__2));
00373 u += s[j] * t;
00374 i__3 = j;
00375 i__4 = j;
00376 d__1 = d__ * t;
00377 z__1.r = work[i__4].r + d__1, z__1.i = work[i__4].i;
00378 work[i__3].r = z__1.r, work[i__3].i = z__1.i;
00379 }
00380 i__2 = *n;
00381 for (j = i__ + 1; j <= i__2; ++j) {
00382 i__3 = i__ + j * a_dim1;
00383 t = (d__1 = a[i__3].r, abs(d__1)) + (d__2 = d_imag(&a[i__
00384 + j * a_dim1]), abs(d__2));
00385 u += s[j] * t;
00386 i__3 = j;
00387 i__4 = j;
00388 d__1 = d__ * t;
00389 z__1.r = work[i__4].r + d__1, z__1.i = work[i__4].i;
00390 work[i__3].r = z__1.r, work[i__3].i = z__1.i;
00391 }
00392 } else {
00393 i__2 = i__;
00394 for (j = 1; j <= i__2; ++j) {
00395 i__3 = i__ + j * a_dim1;
00396 t = (d__1 = a[i__3].r, abs(d__1)) + (d__2 = d_imag(&a[i__
00397 + j * a_dim1]), abs(d__2));
00398 u += s[j] * t;
00399 i__3 = j;
00400 i__4 = j;
00401 d__1 = d__ * t;
00402 z__1.r = work[i__4].r + d__1, z__1.i = work[i__4].i;
00403 work[i__3].r = z__1.r, work[i__3].i = z__1.i;
00404 }
00405 i__2 = *n;
00406 for (j = i__ + 1; j <= i__2; ++j) {
00407 i__3 = j + i__ * a_dim1;
00408 t = (d__1 = a[i__3].r, abs(d__1)) + (d__2 = d_imag(&a[j +
00409 i__ * a_dim1]), abs(d__2));
00410 u += s[j] * t;
00411 i__3 = j;
00412 i__4 = j;
00413 d__1 = d__ * t;
00414 z__1.r = work[i__4].r + d__1, z__1.i = work[i__4].i;
00415 work[i__3].r = z__1.r, work[i__3].i = z__1.i;
00416 }
00417 }
00418 i__2 = i__;
00419 z__4.r = u + work[i__2].r, z__4.i = work[i__2].i;
00420 z__3.r = d__ * z__4.r, z__3.i = d__ * z__4.i;
00421 d__1 = (doublereal) (*n);
00422 z__2.r = z__3.r / d__1, z__2.i = z__3.i / d__1;
00423 z__1.r = avg + z__2.r, z__1.i = z__2.i;
00424 avg = z__1.r;
00425 s[i__] = si;
00426 }
00427 }
00428 L999:
00429 smlnum = dlamch_("SAFEMIN");
00430 bignum = 1. / smlnum;
00431 smin = bignum;
00432 smax = 0.;
00433 t = 1. / sqrt(avg);
00434 base = dlamch_("B");
00435 u = 1. / log(base);
00436 i__1 = *n;
00437 for (i__ = 1; i__ <= i__1; ++i__) {
00438 i__2 = (integer) (u * log(s[i__] * t));
00439 s[i__] = pow_di(&base, &i__2);
00440
00441 d__1 = smin, d__2 = s[i__];
00442 smin = min(d__1,d__2);
00443
00444 d__1 = smax, d__2 = s[i__];
00445 smax = max(d__1,d__2);
00446 }
00447 *scond = max(smin,smlnum) / min(smax,bignum);
00448
00449 return 0;
00450 }