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

📄 slaein.c

📁 提供矩阵类的函数库
💻 C
📖 第 1 页 / 共 2 页
字号:
#include "blaswrap.h"
/*  -- translated by f2c (version 19990503).
   You must link the resulting object file with the libraries:
	-lf2c -lm   (in that order)
*/

#include "f2c.h"

/* Common Block Declarations */

struct {
    real ops, itcnt;
} latime_;

#define latime_1 latime_

/* Table of constant values */

static integer c__1 = 1;

/* Subroutine */ int slaein_(logical *rightv, logical *noinit, integer *n, 
	real *h__, integer *ldh, real *wr, real *wi, real *vr, real *vi, real 
	*b, integer *ldb, real *work, real *eps3, real *smlnum, real *bignum, 
	integer *info)
{
    /* System generated locals */
    integer b_dim1, b_offset, h_dim1, h_offset, i__1, i__2, i__3, i__4;
    real r__1, r__2, r__3, r__4;

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

    /* Local variables */
    static integer ierr;
    static real temp, norm, vmax, opst;
    extern doublereal snrm2_(integer *, real *, integer *);
    static integer i__, j;
    static real scale, w, x, y;
    extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *);
    static char trans[1];
    static real vcrit;
    extern doublereal sasum_(integer *, real *, integer *);
    static integer i1, i2, i3;
    static real rootn, vnorm, w1;
    extern doublereal slapy2_(real *, real *);
    static real ei, ej, absbii, absbjj, xi, xr;
    extern integer isamax_(integer *, real *, integer *);
    extern /* Subroutine */ int sladiv_(real *, real *, real *, real *, real *
	    , real *);
    static char normin[1];
    static real nrmsml;
    extern /* Subroutine */ int slatrs_(char *, char *, char *, char *, 
	    integer *, real *, integer *, real *, real *, real *, integer *);
    static real growto, rec;
    static integer its;


#define b_ref(a_1,a_2) b[(a_2)*b_dim1 + a_1]
#define h___ref(a_1,a_2) h__[(a_2)*h_dim1 + a_1]


/*  -- LAPACK auxiliary routine (instrumented to count operations) --   
       Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,   
       Courant Institute, Argonne National Lab, and Rice University   
       September 30, 1994   

       Common block to return operation count.   

    Purpose   
    =======   

    SLAEIN uses inverse iteration to find a right or left eigenvector   
    corresponding to the eigenvalue (WR,WI) of a real upper Hessenberg   
    matrix H.   

    Arguments   
    =========   

    RIGHTV   (input) LOGICAL   
            = .TRUE. : compute right eigenvector;   
            = .FALSE.: compute left eigenvector.   

    NOINIT   (input) LOGICAL   
            = .TRUE. : no initial vector supplied in (VR,VI).   
            = .FALSE.: initial vector supplied in (VR,VI).   

    N       (input) INTEGER   
            The order of the matrix H.  N >= 0.   

    H       (input) REAL array, dimension (LDH,N)   
            The upper Hessenberg matrix H.   

    LDH     (input) INTEGER   
            The leading dimension of the array H.  LDH >= max(1,N).   

    WR      (input) REAL   
    WI      (input) REAL   
            The real and imaginary parts of the eigenvalue of H whose   
            corresponding right or left eigenvector is to be computed.   

    VR      (input/output) REAL array, dimension (N)   
    VI      (input/output) REAL array, dimension (N)   
            On entry, if NOINIT = .FALSE. and WI = 0.0, VR must contain   
            a real starting vector for inverse iteration using the real   
            eigenvalue WR; if NOINIT = .FALSE. and WI.ne.0.0, VR and VI   
            must contain the real and imaginary parts of a complex   
            starting vector for inverse iteration using the complex   
            eigenvalue (WR,WI); otherwise VR and VI need not be set.   
            On exit, if WI = 0.0 (real eigenvalue), VR contains the   
            computed real eigenvector; if WI.ne.0.0 (complex eigenvalue),   
            VR and VI contain the real and imaginary parts of the   
            computed complex eigenvector. The eigenvector is normalized   
            so that the component of largest magnitude has magnitude 1;   
            here the magnitude of a complex number (x,y) is taken to be   
            |x| + |y|.   
            VI is not referenced if WI = 0.0.   

    B       (workspace) REAL array, dimension (LDB,N)   

    LDB     (input) INTEGER   
            The leading dimension of the array B.  LDB >= N+1.   

    WORK   (workspace) REAL array, dimension (N)   

    EPS3    (input) REAL   
            A small machine-dependent value which is used to perturb   
            close eigenvalues, and to replace zero pivots.   

    SMLNUM  (input) REAL   
            A machine-dependent value close to the underflow threshold.   

    BIGNUM  (input) REAL   
            A machine-dependent value close to the overflow threshold.   

    INFO    (output) INTEGER   
            = 0:  successful exit   
            = 1:  inverse iteration did not converge; VR is set to the   
                  last iterate, and so is VI if WI.ne.0.0.   

    =====================================================================   


       Parameter adjustments */
    h_dim1 = *ldh;
    h_offset = 1 + h_dim1 * 1;
    h__ -= h_offset;
    --vr;
    --vi;
    b_dim1 = *ldb;
    b_offset = 1 + b_dim1 * 1;
    b -= b_offset;
    --work;

    /* Function Body */
    *info = 0;
/* **   
       Initialize */
    opst = 0.f;
/* **   

       GROWTO is the threshold used in the acceptance test for an   
       eigenvector. */

    rootn = sqrt((real) (*n));
    growto = .1f / rootn;
/* Computing MAX */
    r__1 = 1.f, r__2 = *eps3 * rootn;
    nrmsml = dmax(r__1,r__2) * *smlnum;
/* **   
          Increment op count for computing ROOTN, GROWTO and NRMSML */
    opst += 4;
/* **   

       Form B = H - (WR,WI)*I (except that the subdiagonal elements and   
       the imaginary parts of the diagonal elements are not stored). */

    i__1 = *n;
    for (j = 1; j <= i__1; ++j) {
	i__2 = j - 1;
	for (i__ = 1; i__ <= i__2; ++i__) {
	    b_ref(i__, j) = h___ref(i__, j);
/* L10: */
	}
	b_ref(j, j) = h___ref(j, j) - *wr;
/* L20: */
    }
/* ** */
    opst += *n;
/* ** */

    if (*wi == 0.f) {

/*        Real eigenvalue. */

	if (*noinit) {

/*           Set initial vector. */

	    i__1 = *n;
	    for (i__ = 1; i__ <= i__1; ++i__) {
		vr[i__] = *eps3;
/* L30: */
	    }
	} else {

/*           Scale supplied initial vector. */

	    vnorm = snrm2_(n, &vr[1], &c__1);
	    r__1 = *eps3 * rootn / dmax(vnorm,nrmsml);
	    sscal_(n, &r__1, &vr[1], &c__1);
/* ** */
	    opst += *n * 3 + 2;
/* ** */
	}

	if (*rightv) {

/*           LU decomposition with partial pivoting of B, replacing zero   
             pivots by EPS3. */

	    i__1 = *n - 1;
	    for (i__ = 1; i__ <= i__1; ++i__) {
		ei = h___ref(i__ + 1, i__);
		if ((r__1 = b_ref(i__, i__), dabs(r__1)) < dabs(ei)) {

/*                 Interchange rows and eliminate. */

		    x = b_ref(i__, i__) / ei;
		    b_ref(i__, i__) = ei;
		    i__2 = *n;
		    for (j = i__ + 1; j <= i__2; ++j) {
			temp = b_ref(i__ + 1, j);
			b_ref(i__ + 1, j) = b_ref(i__, j) - x * temp;
			b_ref(i__, j) = temp;
/* L40: */
		    }
		} else {

/*                 Eliminate without interchange. */

		    if (b_ref(i__, i__) == 0.f) {
			b_ref(i__, i__) = *eps3;
		    }
		    x = ei / b_ref(i__, i__);
		    if (x != 0.f) {
			i__2 = *n;
			for (j = i__ + 1; j <= i__2; ++j) {
			    b_ref(i__ + 1, j) = b_ref(i__ + 1, j) - x * b_ref(
				    i__, j);
/* L50: */
			}
		    }
		}
/* L60: */
	    }
	    if (b_ref(*n, *n) == 0.f) {
		b_ref(*n, *n) = *eps3;
	    }
/* **   
             Increment op count for LU decomposition */
	    latime_1.ops += (*n - 1) * (*n + 1);
/* ** */

	    *(unsigned char *)trans = 'N';

	} else {

/*           UL decomposition with partial pivoting of B, replacing zero   
             pivots by EPS3. */

	    for (j = *n; j >= 2; --j) {
		ej = h___ref(j, j - 1);
		if ((r__1 = b_ref(j, j), dabs(r__1)) < dabs(ej)) {

/*                 Interchange columns and eliminate. */

		    x = b_ref(j, j) / ej;
		    b_ref(j, j) = ej;
		    i__1 = j - 1;
		    for (i__ = 1; i__ <= i__1; ++i__) {
			temp = b_ref(i__, j - 1);
			b_ref(i__, j - 1) = b_ref(i__, j) - x * temp;
			b_ref(i__, j) = temp;
/* L70: */
		    }
		} else {

/*                 Eliminate without interchange. */

		    if (b_ref(j, j) == 0.f) {
			b_ref(j, j) = *eps3;
		    }
		    x = ej / b_ref(j, j);
		    if (x != 0.f) {
			i__1 = j - 1;
			for (i__ = 1; i__ <= i__1; ++i__) {
			    b_ref(i__, j - 1) = b_ref(i__, j - 1) - x * b_ref(
				    i__, j);
/* L80: */
			}
		    }
		}
/* L90: */
	    }
	    if (b_ref(1, 1) == 0.f) {
		b_ref(1, 1) = *eps3;
	    }
/* **   
             Increment op count for UL decomposition */
	    latime_1.ops += (*n - 1) * (*n + 1);
/* ** */

	    *(unsigned char *)trans = 'T';

	}

	*(unsigned char *)normin = 'N';
	i__1 = *n;
	for (its = 1; its <= i__1; ++its) {

/*           Solve U*x = scale*v for a right eigenvector   
               or U'*x = scale*v for a left eigenvector,   
             overwriting x on v. */

	    slatrs_("Upper", trans, "Nonunit", normin, n, &b[b_offset], ldb, &
		    vr[1], &scale, &work[1], &ierr);
/* **   
             Increment opcount for triangular solver, assuming that   
             ops SLATRS = ops STRSV, with no scaling in SLATRS. */
	    latime_1.ops += *n * *n;
/* ** */
	    *(unsigned char *)normin = 'Y';

/*           Test for sufficient growth in the norm of v. */

	    vnorm = sasum_(n, &vr[1], &c__1);
/* ** */
	    opst += *n;
/* ** */
	    if (vnorm >= growto * scale) {
		goto L120;
	    }

/*           Choose new orthogonal starting vector and try again. */

	    temp = *eps3 / (rootn + 1.f);
	    vr[1] = *eps3;
	    i__2 = *n;
	    for (i__ = 2; i__ <= i__2; ++i__) {
		vr[i__] = temp;
/* L100: */
	    }
	    vr[*n - its + 1] -= *eps3 * rootn;
/* ** */
	    opst += 4;
/* **   
   L110: */
	}

/*        Failure to find eigenvector in N iterations. */

	*info = 1;

L120:

/*        Normalize eigenvector. */

	i__ = isamax_(n, &vr[1], &c__1);
	r__2 = 1.f / (r__1 = vr[i__], dabs(r__1));
	sscal_(n, &r__2, &vr[1], &c__1);
/* ** */
	opst += (*n << 1) + 1;

⌨️ 快捷键说明

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