slanv2.c
Go to the documentation of this file.
00001 /* slanv2.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_b4 = 1.f;
00019 
00020 /* Subroutine */ int slanv2_(real *a, real *b, real *c__, real *d__, real *
00021         rt1r, real *rt1i, real *rt2r, real *rt2i, real *cs, real *sn)
00022 {
00023     /* System generated locals */
00024     real r__1, r__2;
00025 
00026     /* Builtin functions */
00027     double r_sign(real *, real *), sqrt(doublereal);
00028 
00029     /* Local variables */
00030     real p, z__, aa, bb, cc, dd, cs1, sn1, sab, sac, eps, tau, temp, scale, 
00031             bcmax, bcmis, sigma;
00032     extern doublereal slapy2_(real *, real *), slamch_(char *);
00033 
00034 
00035 /*  -- LAPACK driver routine (version 3.2) -- */
00036 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00037 /*     November 2006 */
00038 
00039 /*     .. Scalar Arguments .. */
00040 /*     .. */
00041 
00042 /*  Purpose */
00043 /*  ======= */
00044 
00045 /*  SLANV2 computes the Schur factorization of a real 2-by-2 nonsymmetric */
00046 /*  matrix in standard form: */
00047 
00048 /*       [ A  B ] = [ CS -SN ] [ AA  BB ] [ CS  SN ] */
00049 /*       [ C  D ]   [ SN  CS ] [ CC  DD ] [-SN  CS ] */
00050 
00051 /*  where either */
00052 /*  1) CC = 0 so that AA and DD are real eigenvalues of the matrix, or */
00053 /*  2) AA = DD and BB*CC < 0, so that AA + or - sqrt(BB*CC) are complex */
00054 /*  conjugate eigenvalues. */
00055 
00056 /*  Arguments */
00057 /*  ========= */
00058 
00059 /*  A       (input/output) REAL */
00060 /*  B       (input/output) REAL */
00061 /*  C       (input/output) REAL */
00062 /*  D       (input/output) REAL */
00063 /*          On entry, the elements of the input matrix. */
00064 /*          On exit, they are overwritten by the elements of the */
00065 /*          standardised Schur form. */
00066 
00067 /*  RT1R    (output) REAL */
00068 /*  RT1I    (output) REAL */
00069 /*  RT2R    (output) REAL */
00070 /*  RT2I    (output) REAL */
00071 /*          The real and imaginary parts of the eigenvalues. If the */
00072 /*          eigenvalues are a complex conjugate pair, RT1I > 0. */
00073 
00074 /*  CS      (output) REAL */
00075 /*  SN      (output) REAL */
00076 /*          Parameters of the rotation matrix. */
00077 
00078 /*  Further Details */
00079 /*  =============== */
00080 
00081 /*  Modified by V. Sima, Research Institute for Informatics, Bucharest, */
00082 /*  Romania, to reduce the risk of cancellation errors, */
00083 /*  when computing real eigenvalues, and to ensure, if possible, that */
00084 /*  abs(RT1R) >= abs(RT2R). */
00085 
00086 /*  ===================================================================== */
00087 
00088 /*     .. Parameters .. */
00089 /*     .. */
00090 /*     .. Local Scalars .. */
00091 /*     .. */
00092 /*     .. External Functions .. */
00093 /*     .. */
00094 /*     .. Intrinsic Functions .. */
00095 /*     .. */
00096 /*     .. Executable Statements .. */
00097 
00098     eps = slamch_("P");
00099     if (*c__ == 0.f) {
00100         *cs = 1.f;
00101         *sn = 0.f;
00102         goto L10;
00103 
00104     } else if (*b == 0.f) {
00105 
00106 /*        Swap rows and columns */
00107 
00108         *cs = 0.f;
00109         *sn = 1.f;
00110         temp = *d__;
00111         *d__ = *a;
00112         *a = temp;
00113         *b = -(*c__);
00114         *c__ = 0.f;
00115         goto L10;
00116     } else if (*a - *d__ == 0.f && r_sign(&c_b4, b) != r_sign(&c_b4, c__)) {
00117         *cs = 1.f;
00118         *sn = 0.f;
00119         goto L10;
00120     } else {
00121 
00122         temp = *a - *d__;
00123         p = temp * .5f;
00124 /* Computing MAX */
00125         r__1 = dabs(*b), r__2 = dabs(*c__);
00126         bcmax = dmax(r__1,r__2);
00127 /* Computing MIN */
00128         r__1 = dabs(*b), r__2 = dabs(*c__);
00129         bcmis = dmin(r__1,r__2) * r_sign(&c_b4, b) * r_sign(&c_b4, c__);
00130 /* Computing MAX */
00131         r__1 = dabs(p);
00132         scale = dmax(r__1,bcmax);
00133         z__ = p / scale * p + bcmax / scale * bcmis;
00134 
00135 /*        If Z is of the order of the machine accuracy, postpone the */
00136 /*        decision on the nature of eigenvalues */
00137 
00138         if (z__ >= eps * 4.f) {
00139 
00140 /*           Real eigenvalues. Compute A and D. */
00141 
00142             r__1 = sqrt(scale) * sqrt(z__);
00143             z__ = p + r_sign(&r__1, &p);
00144             *a = *d__ + z__;
00145             *d__ -= bcmax / z__ * bcmis;
00146 
00147 /*           Compute B and the rotation matrix */
00148 
00149             tau = slapy2_(c__, &z__);
00150             *cs = z__ / tau;
00151             *sn = *c__ / tau;
00152             *b -= *c__;
00153             *c__ = 0.f;
00154         } else {
00155 
00156 /*           Complex eigenvalues, or real (almost) equal eigenvalues. */
00157 /*           Make diagonal elements equal. */
00158 
00159             sigma = *b + *c__;
00160             tau = slapy2_(&sigma, &temp);
00161             *cs = sqrt((dabs(sigma) / tau + 1.f) * .5f);
00162             *sn = -(p / (tau * *cs)) * r_sign(&c_b4, &sigma);
00163 
00164 /*           Compute [ AA  BB ] = [ A  B ] [ CS -SN ] */
00165 /*                   [ CC  DD ]   [ C  D ] [ SN  CS ] */
00166 
00167             aa = *a * *cs + *b * *sn;
00168             bb = -(*a) * *sn + *b * *cs;
00169             cc = *c__ * *cs + *d__ * *sn;
00170             dd = -(*c__) * *sn + *d__ * *cs;
00171 
00172 /*           Compute [ A  B ] = [ CS  SN ] [ AA  BB ] */
00173 /*                   [ C  D ]   [-SN  CS ] [ CC  DD ] */
00174 
00175             *a = aa * *cs + cc * *sn;
00176             *b = bb * *cs + dd * *sn;
00177             *c__ = -aa * *sn + cc * *cs;
00178             *d__ = -bb * *sn + dd * *cs;
00179 
00180             temp = (*a + *d__) * .5f;
00181             *a = temp;
00182             *d__ = temp;
00183 
00184             if (*c__ != 0.f) {
00185                 if (*b != 0.f) {
00186                     if (r_sign(&c_b4, b) == r_sign(&c_b4, c__)) {
00187 
00188 /*                    Real eigenvalues: reduce to upper triangular form */
00189 
00190                         sab = sqrt((dabs(*b)));
00191                         sac = sqrt((dabs(*c__)));
00192                         r__1 = sab * sac;
00193                         p = r_sign(&r__1, c__);
00194                         tau = 1.f / sqrt((r__1 = *b + *c__, dabs(r__1)));
00195                         *a = temp + p;
00196                         *d__ = temp - p;
00197                         *b -= *c__;
00198                         *c__ = 0.f;
00199                         cs1 = sab * tau;
00200                         sn1 = sac * tau;
00201                         temp = *cs * cs1 - *sn * sn1;
00202                         *sn = *cs * sn1 + *sn * cs1;
00203                         *cs = temp;
00204                     }
00205                 } else {
00206                     *b = -(*c__);
00207                     *c__ = 0.f;
00208                     temp = *cs;
00209                     *cs = -(*sn);
00210                     *sn = temp;
00211                 }
00212             }
00213         }
00214 
00215     }
00216 
00217 L10:
00218 
00219 /*     Store eigenvalues in (RT1R,RT1I) and (RT2R,RT2I). */
00220 
00221     *rt1r = *a;
00222     *rt2r = *d__;
00223     if (*c__ == 0.f) {
00224         *rt1i = 0.f;
00225         *rt2i = 0.f;
00226     } else {
00227         *rt1i = sqrt((dabs(*b))) * sqrt((dabs(*c__)));
00228         *rt2i = -(*rt1i);
00229     }
00230     return 0;
00231 
00232 /*     End of SLANV2 */
00233 
00234 } /* slanv2_ */


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