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


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