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


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:55:46