zgegv.c
来自「算断裂的」· C语言 代码 · 共 705 行 · 第 1/2 页
C
705 行
#include "f2c.h"
/* Subroutine */ int zgegv_(char *jobvl, char *jobvr, integer *n,
doublecomplex *a, integer *lda, doublecomplex *b, integer *ldb,
doublecomplex *alpha, doublecomplex *beta, doublecomplex *vl, integer
*ldvl, doublecomplex *vr, integer *ldvr, doublecomplex *work, integer
*lwork, doublereal *rwork, integer *info)
{
/* -- LAPACK driver routine (version 2.0) --
Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
Courant Institute, Argonne National Lab, and Rice University
September 30, 1994
Purpose
=======
ZGEGV computes for a pair of N-by-N complex nonsymmetric matrices A
and B, the generalized eigenvalues (alpha, beta), and optionally,
the left and/or right generalized eigenvectors (VL and VR).
A generalized eigenvalue for a pair of matrices (A,B) is, roughly
speaking, a scalar w or a ratio alpha/beta = w, such that A - w*B
is singular. It is usually represented as the pair (alpha,beta),
as there is a reasonable interpretation for beta=0, and even for
both being zero. A good beginning reference is the book, "Matrix
Computations", by G. Golub & C. van Loan (Johns Hopkins U. Press)
A right generalized eigenvector corresponding to a generalized
eigenvalue w for a pair of matrices (A,B) is a vector r such
that (A - w B) r = 0 . A left generalized eigenvector is a vector
l such that l**H * (A - w B) = 0, where l**H is the
conjugate-transpose of l.
Note: this routine performs "full balancing" on A and B -- see
"Further Details", below.
Arguments
=========
JOBVL (input) CHARACTER*1
= 'N': do not compute the left generalized eigenvectors;
= 'V': compute the left generalized eigenvectors.
JOBVR (input) CHARACTER*1
= 'N': do not compute the right generalized eigenvectors;
= 'V': compute the right generalized eigenvectors.
N (input) INTEGER
The order of the matrices A, B, VL, and VR. N >= 0.
A (input/output) COMPLEX*16 array, dimension (LDA, N)
On entry, the first of the pair of matrices whose
generalized eigenvalues and (optionally) generalized
eigenvectors are to be computed.
On exit, the contents will have been destroyed. (For a
description of the contents of A on exit, see "Further
Details", below.)
LDA (input) INTEGER
The leading dimension of A. LDA >= max(1,N).
B (input/output) COMPLEX*16 array, dimension (LDB, N)
On entry, the second of the pair of matrices whose
generalized eigenvalues and (optionally) generalized
eigenvectors are to be computed.
On exit, the contents will have been destroyed. (For a
description of the contents of B on exit, see "Further
Details", below.)
LDB (input) INTEGER
The leading dimension of B. LDB >= max(1,N).
ALPHA (output) COMPLEX*16 array, dimension (N)
BETA (output) COMPLEX*16 array, dimension (N)
On exit, ALPHA(j)/BETA(j), j=1,...,N, will be the
generalized eigenvalues.
Note: the quotients ALPHA(j)/BETA(j) may easily over- or
underflow, and BETA(j) may even be zero. Thus, the user
should avoid naively computing the ratio alpha/beta.
However, ALPHA will be always less than and usually
comparable with norm(A) in magnitude, and BETA always less
than and usually comparable with norm(B).
VL (output) COMPLEX*16 array, dimension (LDVL,N)
If JOBVL = 'V', the left generalized eigenvectors. (See
"Purpose", above.)
Each eigenvector will be scaled so the largest component
will have abs(real part) + abs(imag. part) = 1, *except*
that for eigenvalues with alpha=beta=0, a zero vector will
be returned as the corresponding eigenvector.
Not referenced if JOBVL = 'N'.
LDVL (input) INTEGER
The leading dimension of the matrix VL. LDVL >= 1, and
if JOBVL = 'V', LDVL >= N.
VR (output) COMPLEX*16 array, dimension (LDVR,N)
If JOBVL = 'V', the right generalized eigenvectors. (See
"Purpose", above.)
Each eigenvector will be scaled so the largest component
will have abs(real part) + abs(imag. part) = 1, *except*
that for eigenvalues with alpha=beta=0, a zero vector will
be returned as the corresponding eigenvector.
Not referenced if JOBVR = 'N'.
LDVR (input) INTEGER
The leading dimension of the matrix VR. LDVR >= 1, and
if JOBVR = 'V', LDVR >= N.
WORK (workspace/output) COMPLEX*16 array, dimension (LWORK)
On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
LWORK (input) INTEGER
The dimension of the array WORK. LWORK >= max(1,2*N).
For good performance, LWORK must generally be larger.
To compute the optimal value of LWORK, call ILAENV to get
blocksizes (for ZGEQRF, ZUNMQR, and CUNGQR.) Then compute:
NB -- MAX of the blocksizes for ZGEQRF, ZUNMQR, and CUNGQR;
The optimal LWORK is MAX( 2*N, N*(NB+1) ).
RWORK (workspace/output) DOUBLE PRECISION array, dimension (8*N)
INFO (output) INTEGER
= 0: successful exit
< 0: if INFO = -i, the i-th argument had an illegal value.
=1,...,N:
The QZ iteration failed. No eigenvectors have been
calculated, but ALPHA(j) and BETA(j) should be
correct for j=INFO+1,...,N.
> N: errors that usually indicate LAPACK problems:
=N+1: error return from ZGGBAL
=N+2: error return from ZGEQRF
=N+3: error return from ZUNMQR
=N+4: error return from ZUNGQR
=N+5: error return from ZGGHRD
=N+6: error return from ZHGEQZ (other than failed
iteration)
=N+7: error return from ZTGEVC
=N+8: error return from ZGGBAK (computing VL)
=N+9: error return from ZGGBAK (computing VR)
=N+10: error return from ZLASCL (various calls)
Further Details
===============
Balancing
---------
This driver calls ZGGBAL to both permute and scale rows and columns
of A and B. The permutations PL and PR are chosen so that PL*A*PR
and PL*B*R will be upper triangular except for the diagonal blocks
A(i:j,i:j) and B(i:j,i:j), with i and j as close together as
possible. The diagonal scaling matrices DL and DR are chosen so
that the pair DL*PL*A*PR*DR, DL*PL*B*PR*DR have elements close to
one (except for the elements that start out zero.)
After the eigenvalues and eigenvectors of the balanced matrices
have been computed, ZGGBAK transforms the eigenvectors back to what
they would have been (in perfect arithmetic) if they had not been
balanced.
Contents of A and B on Exit
-------- -- - --- - -- ----
If any eigenvectors are computed (either JOBVL='V' or JOBVR='V' or
both), then on exit the arrays A and B will contain the complex Schur
form[*] of the "balanced" versions of A and B. If no eigenvectors
are computed, then only the diagonal blocks will be correct.
[*] In other words, upper triangular form.
=====================================================================
Decode the input arguments
Parameter adjustments
Function Body */
/* Table of constant values */
static doublecomplex c_b1 = {0.,0.};
static doublecomplex c_b2 = {1.,0.};
static integer c_n1 = -1;
static doublereal c_b16 = 1.;
static integer c__1 = 1;
/* System generated locals */
integer a_dim1, a_offset, b_dim1, b_offset, vl_dim1, vl_offset, vr_dim1,
vr_offset, i__1, i__2, i__3, i__4;
doublereal d__1, d__2, d__3, d__4;
doublecomplex z__1, z__2;
/* Builtin functions */
double d_imag(doublecomplex *);
/* Local variables */
static doublereal absb, anrm, bnrm;
static integer itau;
static doublereal temp;
static logical ilvl, ilvr;
static doublereal anrm1, anrm2, bnrm1, bnrm2, absai, scale, absar, sbeta;
extern logical lsame_(char *, char *);
static integer ileft, iinfo, icols, iwork, irows, jc, in;
extern doublereal dlamch_(char *);
static integer jr;
static doublereal salfai;
extern /* Subroutine */ int zggbak_(char *, char *, integer *, integer *,
integer *, doublereal *, doublereal *, integer *, doublecomplex *,
integer *, integer *), zggbal_(char *, integer *,
doublecomplex *, integer *, doublecomplex *, integer *, integer *
, integer *, doublereal *, doublereal *, doublereal *, integer *);
static doublereal salfar, safmin;
extern /* Subroutine */ int xerbla_(char *, integer *);
static doublereal safmax;
static char chtemp[1];
static logical ldumma[1];
extern doublereal zlange_(char *, integer *, integer *, doublecomplex *,
integer *, doublereal *);
static integer ijobvl, iright;
static logical ilimit;
extern /* Subroutine */ int zgghrd_(char *, char *, integer *, integer *,
integer *, doublecomplex *, integer *, doublecomplex *, integer *,
doublecomplex *, integer *, doublecomplex *, integer *, integer *
), zlascl_(char *, integer *, integer *,
doublereal *, doublereal *, integer *, integer *, doublecomplex *,
integer *, integer *);
static integer ijobvr;
extern /* Subroutine */ int zgeqrf_(integer *, integer *, doublecomplex *,
integer *, doublecomplex *, doublecomplex *, integer *, integer *
);
static integer lwkmin;
extern /* Subroutine */ int zlacpy_(char *, integer *, integer *,
doublecomplex *, integer *, doublecomplex *, integer *),
zlaset_(char *, integer *, integer *, doublecomplex *,
doublecomplex *, doublecomplex *, integer *), ztgevc_(
char *, char *, logical *, integer *, doublecomplex *, integer *,
doublecomplex *, integer *, doublecomplex *, integer *,
doublecomplex *, integer *, integer *, integer *, doublecomplex *,
doublereal *, integer *), zhgeqz_(char *, char *,
char *, integer *, integer *, integer *, doublecomplex *,
integer *, doublecomplex *, integer *, doublecomplex *,
doublecomplex *, doublecomplex *, integer *, doublecomplex *,
integer *, doublecomplex *, integer *, doublereal *, integer *);
static integer irwork, lwkopt;
extern /* Subroutine */ int zungqr_(integer *, integer *, integer *,
doublecomplex *, integer *, doublecomplex *, doublecomplex *,
integer *, integer *), zunmqr_(char *, char *, integer *, integer
*, integer *, doublecomplex *, integer *, doublecomplex *,
doublecomplex *, integer *, doublecomplex *, integer *, integer *);
static integer ihi, ilo;
static doublereal eps;
static logical ilv;
#define ALPHA(I) alpha[(I)-1]
#define BETA(I) beta[(I)-1]
#define WORK(I) work[(I)-1]
#define RWORK(I) rwork[(I)-1]
#define A(I,J) a[(I)-1 + ((J)-1)* ( *lda)]
#define B(I,J) b[(I)-1 + ((J)-1)* ( *ldb)]
#define VL(I,J) vl[(I)-1 + ((J)-1)* ( *ldvl)]
#define VR(I,J) vr[(I)-1 + ((J)-1)* ( *ldvr)]
if (lsame_(jobvl, "N")) {
ijobvl = 1;
ilvl = FALSE_;
} else if (lsame_(jobvl, "V")) {
ijobvl = 2;
ilvl = TRUE_;
} else {
ijobvl = -1;
ilvl = FALSE_;
}
if (lsame_(jobvr, "N")) {
ijobvr = 1;
ilvr = FALSE_;
} else if (lsame_(jobvr, "V")) {
ijobvr = 2;
ilvr = TRUE_;
} else {
ijobvr = -1;
ilvr = FALSE_;
}
ilv = ilvl || ilvr;
/* Test the input arguments
Computing MAX */
i__1 = *n << 1;
lwkmin = max(i__1,1);
lwkopt = lwkmin;
*info = 0;
if (ijobvl <= 0) {
*info = -1;
} else if (ijobvr <= 0) {
*info = -2;
} else if (*n < 0) {
*info = -3;
} else if (*lda < max(1,*n)) {
*info = -5;
} else if (*ldb < max(1,*n)) {
*info = -7;
} else if (*ldvl < 1 || ilvl && *ldvl < *n) {
*info = -11;
} else if (*ldvr < 1 || ilvr && *ldvr < *n) {
*info = -13;
} else if (*lwork < lwkmin) {
*info = -15;
}
if (*info != 0) {
i__1 = -(*info);
xerbla_("ZGEGV ", &i__1);
return 0;
}
/* Quick return if possible */
WORK(1).r = (doublereal) lwkopt, WORK(1).i = 0.;
if (*n == 0) {
return 0;
}
/* Get machine constants */
eps = dlamch_("E") * dlamch_("B");
safmin = dlamch_("S");
safmin += safmin;
safmax = 1. / safmin;
/* Scale A */
anrm = zlange_("M", n, n, &A(1,1), lda, &RWORK(1));
anrm1 = anrm;
anrm2 = 1.;
if (anrm < 1.) {
if (safmax * anrm < 1.) {
anrm1 = safmin;
anrm2 = safmax * anrm;
}
}
if (anrm > 0.) {
zlascl_("G", &c_n1, &c_n1, &anrm, &c_b16, n, n, &A(1,1), lda, &
iinfo);
if (iinfo != 0) {
*info = *n + 10;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?