⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dlag2.c

📁 DTMK软件开发包,此为开源软件,是一款很好的医学图像开发资源.
💻 C
📖 第 1 页 / 共 2 页
字号:
/* lapack/double/dlag2.f -- translated by f2c (version 20050501).
   You must link the resulting object file with libf2c:
        on Microsoft Windows system, link with libf2c.lib;
        on Linux or Unix systems, link with .../path/to/libf2c.a -lm
        or, if you install libf2c.a in a standard place, with -lf2c -lm
        -- in that order, at the end of the command line, as in
                cc *.o -lf2c -lm
        Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,

                http://www.netlib.org/f2c/libf2c.zip
*/

#ifdef __cplusplus
extern "C" {
#endif
#include "v3p_netlib.h"

/*<    >*/
/* Subroutine */ int dlag2_(doublereal *a, integer *lda, doublereal *b, 
        integer *ldb, doublereal *safmin, doublereal *scale1, doublereal *
        scale2, doublereal *wr1, doublereal *wr2, doublereal *wi)
{
    /* System generated locals */
    integer a_dim1, a_offset, b_dim1, b_offset;
    doublereal d__1, d__2, d__3, d__4, d__5, d__6;

    /* Builtin functions */
    double sqrt(doublereal), d_sign(doublereal *, doublereal *);

    /* Local variables */
    doublereal r__, c1, c2, c3, c4, c5, s1, s2, a11, a12, a21, a22, b11, b12, 
            b22, pp, qq, ss, as11, as12, as22, sum, abi22, diff, bmin, wbig, 
            wabs, wdet, binv11, binv22, discr, anorm, bnorm, bsize, shift, 
            rtmin, rtmax, wsize, ascale, bscale, wscale, safmax, wsmall;


/*  -- LAPACK auxiliary routine (version 3.0) -- */
/*     Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., */
/*     Courant Institute, Argonne National Lab, and Rice University */
/*     March 31, 1993 */

/*     .. Scalar Arguments .. */
/*<       INTEGER            LDA, LDB >*/
/*<       DOUBLE PRECISION   SAFMIN, SCALE1, SCALE2, WI, WR1, WR2 >*/
/*     .. */
/*     .. Array Arguments .. */
/*<       DOUBLE PRECISION   A( LDA, * ), B( LDB, * ) >*/
/*     .. */

/*  Purpose */
/*  ======= */

/*  DLAG2 computes the eigenvalues of a 2 x 2 generalized eigenvalue */
/*  problem  A - w B, with scaling as necessary to avoid over-/underflow. */

/*  The scaling factor "s" results in a modified eigenvalue equation */

/*      s A - w B */

/*  where  s  is a non-negative scaling factor chosen so that  w,  w B, */
/*  and  s A  do not overflow and, if possible, do not underflow, either. */

/*  Arguments */
/*  ========= */

/*  A       (input) DOUBLE PRECISION array, dimension (LDA, 2) */
/*          On entry, the 2 x 2 matrix A.  It is assumed that its 1-norm */
/*          is less than 1/SAFMIN.  Entries less than */
/*          sqrt(SAFMIN)*norm(A) are subject to being treated as zero. */

/*  LDA     (input) INTEGER */
/*          The leading dimension of the array A.  LDA >= 2. */

/*  B       (input) DOUBLE PRECISION array, dimension (LDB, 2) */
/*          On entry, the 2 x 2 upper triangular matrix B.  It is */
/*          assumed that the one-norm of B is less than 1/SAFMIN.  The */
/*          diagonals should be at least sqrt(SAFMIN) times the largest */
/*          element of B (in absolute value); if a diagonal is smaller */
/*          than that, then  +/- sqrt(SAFMIN) will be used instead of */
/*          that diagonal. */

/*  LDB     (input) INTEGER */
/*          The leading dimension of the array B.  LDB >= 2. */

/*  SAFMIN  (input) DOUBLE PRECISION */
/*          The smallest positive number s.t. 1/SAFMIN does not */
/*          overflow.  (This should always be DLAMCH('S') -- it is an */
/*          argument in order to avoid having to call DLAMCH frequently.) */

/*  SCALE1  (output) DOUBLE PRECISION */
/*          A scaling factor used to avoid over-/underflow in the */
/*          eigenvalue equation which defines the first eigenvalue.  If */
/*          the eigenvalues are complex, then the eigenvalues are */
/*          ( WR1  +/-  WI i ) / SCALE1  (which may lie outside the */
/*          exponent range of the machine), SCALE1=SCALE2, and SCALE1 */
/*          will always be positive.  If the eigenvalues are real, then */
/*          the first (real) eigenvalue is  WR1 / SCALE1 , but this may */
/*          overflow or underflow, and in fact, SCALE1 may be zero or */
/*          less than the underflow threshhold if the exact eigenvalue */
/*          is sufficiently large. */

/*  SCALE2  (output) DOUBLE PRECISION */
/*          A scaling factor used to avoid over-/underflow in the */
/*          eigenvalue equation which defines the second eigenvalue.  If */
/*          the eigenvalues are complex, then SCALE2=SCALE1.  If the */
/*          eigenvalues are real, then the second (real) eigenvalue is */
/*          WR2 / SCALE2 , but this may overflow or underflow, and in */
/*          fact, SCALE2 may be zero or less than the underflow */
/*          threshhold if the exact eigenvalue is sufficiently large. */

/*  WR1     (output) DOUBLE PRECISION */
/*          If the eigenvalue is real, then WR1 is SCALE1 times the */
/*          eigenvalue closest to the (2,2) element of A B**(-1).  If the */
/*          eigenvalue is complex, then WR1=WR2 is SCALE1 times the real */
/*          part of the eigenvalues. */

/*  WR2     (output) DOUBLE PRECISION */
/*          If the eigenvalue is real, then WR2 is SCALE2 times the */
/*          other eigenvalue.  If the eigenvalue is complex, then */
/*          WR1=WR2 is SCALE1 times the real part of the eigenvalues. */

/*  WI      (output) DOUBLE PRECISION */
/*          If the eigenvalue is real, then WI is zero.  If the */
/*          eigenvalue is complex, then WI is SCALE1 times the imaginary */
/*          part of the eigenvalues.  WI will always be non-negative. */

/*  ===================================================================== */

/*     .. Parameters .. */
/*<       DOUBLE PRECISION   ZERO, ONE, TWO >*/
/*<       PARAMETER          ( ZERO = 0.0D+0, ONE = 1.0D+0, TWO = 2.0D+0 ) >*/
/*<       DOUBLE PRECISION   HALF >*/
/*<       PARAMETER          ( HALF = ONE / TWO ) >*/
/*<       DOUBLE PRECISION   FUZZY1 >*/
/*<       PARAMETER          ( FUZZY1 = ONE+1.0D-5 ) >*/
/*     .. */
/*     .. Local Scalars .. */
/*<    >*/
/*     .. */
/*     .. Intrinsic Functions .. */
/*<       INTRINSIC          ABS, MAX, MIN, SIGN, SQRT >*/
/*     .. */
/*     .. Executable Statements .. */

/*<       RTMIN = SQRT( SAFMIN ) >*/
    /* Parameter adjustments */
    a_dim1 = *lda;
    a_offset = 1 + a_dim1;
    a -= a_offset;
    b_dim1 = *ldb;
    b_offset = 1 + b_dim1;
    b -= b_offset;

    /* Function Body */
    rtmin = sqrt(*safmin);
/*<       RTMAX = ONE / RTMIN >*/
    rtmax = 1. / rtmin;
/*<       SAFMAX = ONE / SAFMIN >*/
    safmax = 1. / *safmin;

/*     Scale A */

/*<    >*/
/* Computing MAX */
    d__5 = (d__1 = a[a_dim1 + 1], abs(d__1)) + (d__2 = a[a_dim1 + 2], abs(
            d__2)), d__6 = (d__3 = a[(a_dim1 << 1) + 1], abs(d__3)) + (d__4 = 
            a[(a_dim1 << 1) + 2], abs(d__4)), d__5 = max(d__5,d__6);
    anorm = max(d__5,*safmin);
/*<       ASCALE = ONE / ANORM >*/
    ascale = 1. / anorm;
/*<       A11 = ASCALE*A( 1, 1 ) >*/
    a11 = ascale * a[a_dim1 + 1];
/*<       A21 = ASCALE*A( 2, 1 ) >*/
    a21 = ascale * a[a_dim1 + 2];
/*<       A12 = ASCALE*A( 1, 2 ) >*/
    a12 = ascale * a[(a_dim1 << 1) + 1];
/*<       A22 = ASCALE*A( 2, 2 ) >*/
    a22 = ascale * a[(a_dim1 << 1) + 2];

/*     Perturb B if necessary to insure non-singularity */

/*<       B11 = B( 1, 1 ) >*/
    b11 = b[b_dim1 + 1];
/*<       B12 = B( 1, 2 ) >*/
    b12 = b[(b_dim1 << 1) + 1];
/*<       B22 = B( 2, 2 ) >*/
    b22 = b[(b_dim1 << 1) + 2];
/*<       BMIN = RTMIN*MAX( ABS( B11 ), ABS( B12 ), ABS( B22 ), RTMIN ) >*/
/* Computing MAX */
    d__1 = abs(b11), d__2 = abs(b12), d__1 = max(d__1,d__2), d__2 = abs(b22), 
            d__1 = max(d__1,d__2);
    bmin = rtmin * max(d__1,rtmin);
/*<    >*/
    if (abs(b11) < bmin) {
        b11 = d_sign(&bmin, &b11);
    }
/*<    >*/
    if (abs(b22) < bmin) {
        b22 = d_sign(&bmin, &b22);
    }

/*     Scale B */

/*<       BNORM = MAX( ABS( B11 ), ABS( B12 )+ABS( B22 ), SAFMIN ) >*/
/* Computing MAX */
    d__1 = abs(b11), d__2 = abs(b12) + abs(b22), d__1 = max(d__1,d__2);
    bnorm = max(d__1,*safmin);
/*<       BSIZE = MAX( ABS( B11 ), ABS( B22 ) ) >*/
/* Computing MAX */
    d__1 = abs(b11), d__2 = abs(b22);
    bsize = max(d__1,d__2);
/*<       BSCALE = ONE / BSIZE >*/
    bscale = 1. / bsize;
/*<       B11 = B11*BSCALE >*/
    b11 *= bscale;
/*<       B12 = B12*BSCALE >*/
    b12 *= bscale;
/*<       B22 = B22*BSCALE >*/
    b22 *= bscale;

/*     Compute larger eigenvalue by method described by C. van Loan */

/*     ( AS is A shifted by -SHIFT*B ) */

/*<       BINV11 = ONE / B11 >*/
    binv11 = 1. / b11;
/*<       BINV22 = ONE / B22 >*/
    binv22 = 1. / b22;
/*<       S1 = A11*BINV11 >*/
    s1 = a11 * binv11;
/*<       S2 = A22*BINV22 >*/
    s2 = a22 * binv22;
/*<       IF( ABS( S1 ).LE.ABS( S2 ) ) THEN >*/
    if (abs(s1) <= abs(s2)) {
/*<          AS12 = A12 - S1*B12 >*/
        as12 = a12 - s1 * b12;
/*<          AS22 = A22 - S1*B22 >*/
        as22 = a22 - s1 * b22;
/*<          SS = A21*( BINV11*BINV22 ) >*/
        ss = a21 * (binv11 * binv22);
/*<          ABI22 = AS22*BINV22 - SS*B12 >*/
        abi22 = as22 * binv22 - ss * b12;
/*<          PP = HALF*ABI22 >*/
        pp = abi22 * .5;
/*<          SHIFT = S1 >*/
        shift = s1;
/*<       ELSE >*/
    } else {
/*<          AS12 = A12 - S2*B12 >*/
        as12 = a12 - s2 * b12;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -