dlags2.c
Go to the documentation of this file.
00001 /* dlags2.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 /* Subroutine */ int dlags2_(logical *upper, doublereal *a1, doublereal *a2, 
00017         doublereal *a3, doublereal *b1, doublereal *b2, doublereal *b3, 
00018         doublereal *csu, doublereal *snu, doublereal *csv, doublereal *snv, 
00019         doublereal *csq, doublereal *snq)
00020 {
00021     /* System generated locals */
00022     doublereal d__1;
00023 
00024     /* Local variables */
00025     doublereal a, b, c__, d__, r__, s1, s2, ua11, ua12, ua21, ua22, vb11, 
00026             vb12, vb21, vb22, csl, csr, snl, snr, aua11, aua12, aua21, aua22, 
00027             avb11, avb12, avb21, avb22, ua11r, ua22r, vb11r, vb22r;
00028     extern /* Subroutine */ int dlasv2_(doublereal *, doublereal *, 
00029             doublereal *, doublereal *, doublereal *, doublereal *, 
00030             doublereal *, doublereal *, doublereal *), dlartg_(doublereal *, 
00031             doublereal *, doublereal *, doublereal *, doublereal *);
00032 
00033 
00034 /*  -- LAPACK auxiliary routine (version 3.2) -- */
00035 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00036 /*     November 2006 */
00037 
00038 /*     .. Scalar Arguments .. */
00039 /*     .. */
00040 
00041 /*  Purpose */
00042 /*  ======= */
00043 
00044 /*  DLAGS2 computes 2-by-2 orthogonal matrices U, V and Q, such */
00045 /*  that if ( UPPER ) then */
00046 
00047 /*            U'*A*Q = U'*( A1 A2 )*Q = ( x  0  ) */
00048 /*                        ( 0  A3 )     ( x  x  ) */
00049 /*  and */
00050 /*            V'*B*Q = V'*( B1 B2 )*Q = ( x  0  ) */
00051 /*                        ( 0  B3 )     ( x  x  ) */
00052 
00053 /*  or if ( .NOT.UPPER ) then */
00054 
00055 /*            U'*A*Q = U'*( A1 0  )*Q = ( x  x  ) */
00056 /*                        ( A2 A3 )     ( 0  x  ) */
00057 /*  and */
00058 /*            V'*B*Q = V'*( B1 0  )*Q = ( x  x  ) */
00059 /*                        ( B2 B3 )     ( 0  x  ) */
00060 
00061 /*  The rows of the transformed A and B are parallel, where */
00062 
00063 /*    U = (  CSU  SNU ), V = (  CSV SNV ), Q = (  CSQ   SNQ ) */
00064 /*        ( -SNU  CSU )      ( -SNV CSV )      ( -SNQ   CSQ ) */
00065 
00066 /*  Z' denotes the transpose of Z. */
00067 
00068 
00069 /*  Arguments */
00070 /*  ========= */
00071 
00072 /*  UPPER   (input) LOGICAL */
00073 /*          = .TRUE.: the input matrices A and B are upper triangular. */
00074 /*          = .FALSE.: the input matrices A and B are lower triangular. */
00075 
00076 /*  A1      (input) DOUBLE PRECISION */
00077 /*  A2      (input) DOUBLE PRECISION */
00078 /*  A3      (input) DOUBLE PRECISION */
00079 /*          On entry, A1, A2 and A3 are elements of the input 2-by-2 */
00080 /*          upper (lower) triangular matrix A. */
00081 
00082 /*  B1      (input) DOUBLE PRECISION */
00083 /*  B2      (input) DOUBLE PRECISION */
00084 /*  B3      (input) DOUBLE PRECISION */
00085 /*          On entry, B1, B2 and B3 are elements of the input 2-by-2 */
00086 /*          upper (lower) triangular matrix B. */
00087 
00088 /*  CSU     (output) DOUBLE PRECISION */
00089 /*  SNU     (output) DOUBLE PRECISION */
00090 /*          The desired orthogonal matrix U. */
00091 
00092 /*  CSV     (output) DOUBLE PRECISION */
00093 /*  SNV     (output) DOUBLE PRECISION */
00094 /*          The desired orthogonal matrix V. */
00095 
00096 /*  CSQ     (output) DOUBLE PRECISION */
00097 /*  SNQ     (output) DOUBLE PRECISION */
00098 /*          The desired orthogonal matrix Q. */
00099 
00100 /*  ===================================================================== */
00101 
00102 /*     .. Parameters .. */
00103 /*     .. */
00104 /*     .. Local Scalars .. */
00105 /*     .. */
00106 /*     .. External Subroutines .. */
00107 /*     .. */
00108 /*     .. Intrinsic Functions .. */
00109 /*     .. */
00110 /*     .. Executable Statements .. */
00111 
00112     if (*upper) {
00113 
00114 /*        Input matrices A and B are upper triangular matrices */
00115 
00116 /*        Form matrix C = A*adj(B) = ( a b ) */
00117 /*                                   ( 0 d ) */
00118 
00119         a = *a1 * *b3;
00120         d__ = *a3 * *b1;
00121         b = *a2 * *b1 - *a1 * *b2;
00122 
00123 /*        The SVD of real 2-by-2 triangular C */
00124 
00125 /*         ( CSL -SNL )*( A B )*(  CSR  SNR ) = ( R 0 ) */
00126 /*         ( SNL  CSL ) ( 0 D ) ( -SNR  CSR )   ( 0 T ) */
00127 
00128         dlasv2_(&a, &b, &d__, &s1, &s2, &snr, &csr, &snl, &csl);
00129 
00130         if (abs(csl) >= abs(snl) || abs(csr) >= abs(snr)) {
00131 
00132 /*           Compute the (1,1) and (1,2) elements of U'*A and V'*B, */
00133 /*           and (1,2) element of |U|'*|A| and |V|'*|B|. */
00134 
00135             ua11r = csl * *a1;
00136             ua12 = csl * *a2 + snl * *a3;
00137 
00138             vb11r = csr * *b1;
00139             vb12 = csr * *b2 + snr * *b3;
00140 
00141             aua12 = abs(csl) * abs(*a2) + abs(snl) * abs(*a3);
00142             avb12 = abs(csr) * abs(*b2) + abs(snr) * abs(*b3);
00143 
00144 /*           zero (1,2) elements of U'*A and V'*B */
00145 
00146             if (abs(ua11r) + abs(ua12) != 0.) {
00147                 if (aua12 / (abs(ua11r) + abs(ua12)) <= avb12 / (abs(vb11r) + 
00148                         abs(vb12))) {
00149                     d__1 = -ua11r;
00150                     dlartg_(&d__1, &ua12, csq, snq, &r__);
00151                 } else {
00152                     d__1 = -vb11r;
00153                     dlartg_(&d__1, &vb12, csq, snq, &r__);
00154                 }
00155             } else {
00156                 d__1 = -vb11r;
00157                 dlartg_(&d__1, &vb12, csq, snq, &r__);
00158             }
00159 
00160             *csu = csl;
00161             *snu = -snl;
00162             *csv = csr;
00163             *snv = -snr;
00164 
00165         } else {
00166 
00167 /*           Compute the (2,1) and (2,2) elements of U'*A and V'*B, */
00168 /*           and (2,2) element of |U|'*|A| and |V|'*|B|. */
00169 
00170             ua21 = -snl * *a1;
00171             ua22 = -snl * *a2 + csl * *a3;
00172 
00173             vb21 = -snr * *b1;
00174             vb22 = -snr * *b2 + csr * *b3;
00175 
00176             aua22 = abs(snl) * abs(*a2) + abs(csl) * abs(*a3);
00177             avb22 = abs(snr) * abs(*b2) + abs(csr) * abs(*b3);
00178 
00179 /*           zero (2,2) elements of U'*A and V'*B, and then swap. */
00180 
00181             if (abs(ua21) + abs(ua22) != 0.) {
00182                 if (aua22 / (abs(ua21) + abs(ua22)) <= avb22 / (abs(vb21) + 
00183                         abs(vb22))) {
00184                     d__1 = -ua21;
00185                     dlartg_(&d__1, &ua22, csq, snq, &r__);
00186                 } else {
00187                     d__1 = -vb21;
00188                     dlartg_(&d__1, &vb22, csq, snq, &r__);
00189                 }
00190             } else {
00191                 d__1 = -vb21;
00192                 dlartg_(&d__1, &vb22, csq, snq, &r__);
00193             }
00194 
00195             *csu = snl;
00196             *snu = csl;
00197             *csv = snr;
00198             *snv = csr;
00199 
00200         }
00201 
00202     } else {
00203 
00204 /*        Input matrices A and B are lower triangular matrices */
00205 
00206 /*        Form matrix C = A*adj(B) = ( a 0 ) */
00207 /*                                   ( c d ) */
00208 
00209         a = *a1 * *b3;
00210         d__ = *a3 * *b1;
00211         c__ = *a2 * *b3 - *a3 * *b2;
00212 
00213 /*        The SVD of real 2-by-2 triangular C */
00214 
00215 /*         ( CSL -SNL )*( A 0 )*(  CSR  SNR ) = ( R 0 ) */
00216 /*         ( SNL  CSL ) ( C D ) ( -SNR  CSR )   ( 0 T ) */
00217 
00218         dlasv2_(&a, &c__, &d__, &s1, &s2, &snr, &csr, &snl, &csl);
00219 
00220         if (abs(csr) >= abs(snr) || abs(csl) >= abs(snl)) {
00221 
00222 /*           Compute the (2,1) and (2,2) elements of U'*A and V'*B, */
00223 /*           and (2,1) element of |U|'*|A| and |V|'*|B|. */
00224 
00225             ua21 = -snr * *a1 + csr * *a2;
00226             ua22r = csr * *a3;
00227 
00228             vb21 = -snl * *b1 + csl * *b2;
00229             vb22r = csl * *b3;
00230 
00231             aua21 = abs(snr) * abs(*a1) + abs(csr) * abs(*a2);
00232             avb21 = abs(snl) * abs(*b1) + abs(csl) * abs(*b2);
00233 
00234 /*           zero (2,1) elements of U'*A and V'*B. */
00235 
00236             if (abs(ua21) + abs(ua22r) != 0.) {
00237                 if (aua21 / (abs(ua21) + abs(ua22r)) <= avb21 / (abs(vb21) + 
00238                         abs(vb22r))) {
00239                     dlartg_(&ua22r, &ua21, csq, snq, &r__);
00240                 } else {
00241                     dlartg_(&vb22r, &vb21, csq, snq, &r__);
00242                 }
00243             } else {
00244                 dlartg_(&vb22r, &vb21, csq, snq, &r__);
00245             }
00246 
00247             *csu = csr;
00248             *snu = -snr;
00249             *csv = csl;
00250             *snv = -snl;
00251 
00252         } else {
00253 
00254 /*           Compute the (1,1) and (1,2) elements of U'*A and V'*B, */
00255 /*           and (1,1) element of |U|'*|A| and |V|'*|B|. */
00256 
00257             ua11 = csr * *a1 + snr * *a2;
00258             ua12 = snr * *a3;
00259 
00260             vb11 = csl * *b1 + snl * *b2;
00261             vb12 = snl * *b3;
00262 
00263             aua11 = abs(csr) * abs(*a1) + abs(snr) * abs(*a2);
00264             avb11 = abs(csl) * abs(*b1) + abs(snl) * abs(*b2);
00265 
00266 /*           zero (1,1) elements of U'*A and V'*B, and then swap. */
00267 
00268             if (abs(ua11) + abs(ua12) != 0.) {
00269                 if (aua11 / (abs(ua11) + abs(ua12)) <= avb11 / (abs(vb11) + 
00270                         abs(vb12))) {
00271                     dlartg_(&ua12, &ua11, csq, snq, &r__);
00272                 } else {
00273                     dlartg_(&vb12, &vb11, csq, snq, &r__);
00274                 }
00275             } else {
00276                 dlartg_(&vb12, &vb11, csq, snq, &r__);
00277             }
00278 
00279             *csu = snr;
00280             *snu = csr;
00281             *csv = snl;
00282             *snv = csl;
00283 
00284         }
00285 
00286     }
00287 
00288     return 0;
00289 
00290 /*     End of DLAGS2 */
00291 
00292 } /* dlags2_ */


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