slaic1.c
Go to the documentation of this file.
00001 /* slaic1.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 integer c__1 = 1;
00019 static real c_b5 = 1.f;
00020 
00021 /* Subroutine */ int slaic1_(integer *job, integer *j, real *x, real *sest, 
00022         real *w, real *gamma, real *sestpr, real *s, real *c__)
00023 {
00024     /* System generated locals */
00025     real r__1, r__2, r__3, r__4;
00026 
00027     /* Builtin functions */
00028     double sqrt(doublereal), r_sign(real *, real *);
00029 
00030     /* Local variables */
00031     real b, t, s1, s2, eps, tmp, sine;
00032     extern doublereal sdot_(integer *, real *, integer *, real *, integer *);
00033     real test, zeta1, zeta2, alpha, norma, absgam, absalp;
00034     extern doublereal slamch_(char *);
00035     real cosine, absest;
00036 
00037 
00038 /*  -- LAPACK auxiliary routine (version 3.2) -- */
00039 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00040 /*     November 2006 */
00041 
00042 /*     .. Scalar Arguments .. */
00043 /*     .. */
00044 /*     .. Array Arguments .. */
00045 /*     .. */
00046 
00047 /*  Purpose */
00048 /*  ======= */
00049 
00050 /*  SLAIC1 applies one step of incremental condition estimation in */
00051 /*  its simplest version: */
00052 
00053 /*  Let x, twonorm(x) = 1, be an approximate singular vector of an j-by-j */
00054 /*  lower triangular matrix L, such that */
00055 /*           twonorm(L*x) = sest */
00056 /*  Then SLAIC1 computes sestpr, s, c such that */
00057 /*  the vector */
00058 /*                  [ s*x ] */
00059 /*           xhat = [  c  ] */
00060 /*  is an approximate singular vector of */
00061 /*                  [ L     0  ] */
00062 /*           Lhat = [ w' gamma ] */
00063 /*  in the sense that */
00064 /*           twonorm(Lhat*xhat) = sestpr. */
00065 
00066 /*  Depending on JOB, an estimate for the largest or smallest singular */
00067 /*  value is computed. */
00068 
00069 /*  Note that [s c]' and sestpr**2 is an eigenpair of the system */
00070 
00071 /*      diag(sest*sest, 0) + [alpha  gamma] * [ alpha ] */
00072 /*                                            [ gamma ] */
00073 
00074 /*  where  alpha =  x'*w. */
00075 
00076 /*  Arguments */
00077 /*  ========= */
00078 
00079 /*  JOB     (input) INTEGER */
00080 /*          = 1: an estimate for the largest singular value is computed. */
00081 /*          = 2: an estimate for the smallest singular value is computed. */
00082 
00083 /*  J       (input) INTEGER */
00084 /*          Length of X and W */
00085 
00086 /*  X       (input) REAL array, dimension (J) */
00087 /*          The j-vector x. */
00088 
00089 /*  SEST    (input) REAL */
00090 /*          Estimated singular value of j by j matrix L */
00091 
00092 /*  W       (input) REAL array, dimension (J) */
00093 /*          The j-vector w. */
00094 
00095 /*  GAMMA   (input) REAL */
00096 /*          The diagonal element gamma. */
00097 
00098 /*  SESTPR  (output) REAL */
00099 /*          Estimated singular value of (j+1) by (j+1) matrix Lhat. */
00100 
00101 /*  S       (output) REAL */
00102 /*          Sine needed in forming xhat. */
00103 
00104 /*  C       (output) REAL */
00105 /*          Cosine needed in forming xhat. */
00106 
00107 /*  ===================================================================== */
00108 
00109 /*     .. Parameters .. */
00110 /*     .. */
00111 /*     .. Local Scalars .. */
00112 /*     .. */
00113 /*     .. Intrinsic Functions .. */
00114 /*     .. */
00115 /*     .. External Functions .. */
00116 /*     .. */
00117 /*     .. Executable Statements .. */
00118 
00119     /* Parameter adjustments */
00120     --w;
00121     --x;
00122 
00123     /* Function Body */
00124     eps = slamch_("Epsilon");
00125     alpha = sdot_(j, &x[1], &c__1, &w[1], &c__1);
00126 
00127     absalp = dabs(alpha);
00128     absgam = dabs(*gamma);
00129     absest = dabs(*sest);
00130 
00131     if (*job == 1) {
00132 
00133 /*        Estimating largest singular value */
00134 
00135 /*        special cases */
00136 
00137         if (*sest == 0.f) {
00138             s1 = dmax(absgam,absalp);
00139             if (s1 == 0.f) {
00140                 *s = 0.f;
00141                 *c__ = 1.f;
00142                 *sestpr = 0.f;
00143             } else {
00144                 *s = alpha / s1;
00145                 *c__ = *gamma / s1;
00146                 tmp = sqrt(*s * *s + *c__ * *c__);
00147                 *s /= tmp;
00148                 *c__ /= tmp;
00149                 *sestpr = s1 * tmp;
00150             }
00151             return 0;
00152         } else if (absgam <= eps * absest) {
00153             *s = 1.f;
00154             *c__ = 0.f;
00155             tmp = dmax(absest,absalp);
00156             s1 = absest / tmp;
00157             s2 = absalp / tmp;
00158             *sestpr = tmp * sqrt(s1 * s1 + s2 * s2);
00159             return 0;
00160         } else if (absalp <= eps * absest) {
00161             s1 = absgam;
00162             s2 = absest;
00163             if (s1 <= s2) {
00164                 *s = 1.f;
00165                 *c__ = 0.f;
00166                 *sestpr = s2;
00167             } else {
00168                 *s = 0.f;
00169                 *c__ = 1.f;
00170                 *sestpr = s1;
00171             }
00172             return 0;
00173         } else if (absest <= eps * absalp || absest <= eps * absgam) {
00174             s1 = absgam;
00175             s2 = absalp;
00176             if (s1 <= s2) {
00177                 tmp = s1 / s2;
00178                 *s = sqrt(tmp * tmp + 1.f);
00179                 *sestpr = s2 * *s;
00180                 *c__ = *gamma / s2 / *s;
00181                 *s = r_sign(&c_b5, &alpha) / *s;
00182             } else {
00183                 tmp = s2 / s1;
00184                 *c__ = sqrt(tmp * tmp + 1.f);
00185                 *sestpr = s1 * *c__;
00186                 *s = alpha / s1 / *c__;
00187                 *c__ = r_sign(&c_b5, gamma) / *c__;
00188             }
00189             return 0;
00190         } else {
00191 
00192 /*           normal case */
00193 
00194             zeta1 = alpha / absest;
00195             zeta2 = *gamma / absest;
00196 
00197             b = (1.f - zeta1 * zeta1 - zeta2 * zeta2) * .5f;
00198             *c__ = zeta1 * zeta1;
00199             if (b > 0.f) {
00200                 t = *c__ / (b + sqrt(b * b + *c__));
00201             } else {
00202                 t = sqrt(b * b + *c__) - b;
00203             }
00204 
00205             sine = -zeta1 / t;
00206             cosine = -zeta2 / (t + 1.f);
00207             tmp = sqrt(sine * sine + cosine * cosine);
00208             *s = sine / tmp;
00209             *c__ = cosine / tmp;
00210             *sestpr = sqrt(t + 1.f) * absest;
00211             return 0;
00212         }
00213 
00214     } else if (*job == 2) {
00215 
00216 /*        Estimating smallest singular value */
00217 
00218 /*        special cases */
00219 
00220         if (*sest == 0.f) {
00221             *sestpr = 0.f;
00222             if (dmax(absgam,absalp) == 0.f) {
00223                 sine = 1.f;
00224                 cosine = 0.f;
00225             } else {
00226                 sine = -(*gamma);
00227                 cosine = alpha;
00228             }
00229 /* Computing MAX */
00230             r__1 = dabs(sine), r__2 = dabs(cosine);
00231             s1 = dmax(r__1,r__2);
00232             *s = sine / s1;
00233             *c__ = cosine / s1;
00234             tmp = sqrt(*s * *s + *c__ * *c__);
00235             *s /= tmp;
00236             *c__ /= tmp;
00237             return 0;
00238         } else if (absgam <= eps * absest) {
00239             *s = 0.f;
00240             *c__ = 1.f;
00241             *sestpr = absgam;
00242             return 0;
00243         } else if (absalp <= eps * absest) {
00244             s1 = absgam;
00245             s2 = absest;
00246             if (s1 <= s2) {
00247                 *s = 0.f;
00248                 *c__ = 1.f;
00249                 *sestpr = s1;
00250             } else {
00251                 *s = 1.f;
00252                 *c__ = 0.f;
00253                 *sestpr = s2;
00254             }
00255             return 0;
00256         } else if (absest <= eps * absalp || absest <= eps * absgam) {
00257             s1 = absgam;
00258             s2 = absalp;
00259             if (s1 <= s2) {
00260                 tmp = s1 / s2;
00261                 *c__ = sqrt(tmp * tmp + 1.f);
00262                 *sestpr = absest * (tmp / *c__);
00263                 *s = -(*gamma / s2) / *c__;
00264                 *c__ = r_sign(&c_b5, &alpha) / *c__;
00265             } else {
00266                 tmp = s2 / s1;
00267                 *s = sqrt(tmp * tmp + 1.f);
00268                 *sestpr = absest / *s;
00269                 *c__ = alpha / s1 / *s;
00270                 *s = -r_sign(&c_b5, gamma) / *s;
00271             }
00272             return 0;
00273         } else {
00274 
00275 /*           normal case */
00276 
00277             zeta1 = alpha / absest;
00278             zeta2 = *gamma / absest;
00279 
00280 /* Computing MAX */
00281             r__3 = zeta1 * zeta1 + 1.f + (r__1 = zeta1 * zeta2, dabs(r__1)), 
00282                     r__4 = (r__2 = zeta1 * zeta2, dabs(r__2)) + zeta2 * zeta2;
00283             norma = dmax(r__3,r__4);
00284 
00285 /*           See if root is closer to zero or to ONE */
00286 
00287             test = (zeta1 - zeta2) * 2.f * (zeta1 + zeta2) + 1.f;
00288             if (test >= 0.f) {
00289 
00290 /*              root is close to zero, compute directly */
00291 
00292                 b = (zeta1 * zeta1 + zeta2 * zeta2 + 1.f) * .5f;
00293                 *c__ = zeta2 * zeta2;
00294                 t = *c__ / (b + sqrt((r__1 = b * b - *c__, dabs(r__1))));
00295                 sine = zeta1 / (1.f - t);
00296                 cosine = -zeta2 / t;
00297                 *sestpr = sqrt(t + eps * 4.f * eps * norma) * absest;
00298             } else {
00299 
00300 /*              root is closer to ONE, shift by that amount */
00301 
00302                 b = (zeta2 * zeta2 + zeta1 * zeta1 - 1.f) * .5f;
00303                 *c__ = zeta1 * zeta1;
00304                 if (b >= 0.f) {
00305                     t = -(*c__) / (b + sqrt(b * b + *c__));
00306                 } else {
00307                     t = b - sqrt(b * b + *c__);
00308                 }
00309                 sine = -zeta1 / t;
00310                 cosine = -zeta2 / (t + 1.f);
00311                 *sestpr = sqrt(t + 1.f + eps * 4.f * eps * norma) * absest;
00312             }
00313             tmp = sqrt(sine * sine + cosine * cosine);
00314             *s = sine / tmp;
00315             *c__ = cosine / tmp;
00316             return 0;
00317 
00318         }
00319     }
00320     return 0;
00321 
00322 /*     End of SLAIC1 */
00323 
00324 } /* slaic1_ */


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:56:10