?sy(he)ev
计算对称(Hermite)矩阵的所有特征值与特征向量。
接口定义
C Interface:
ssyev_(const char *jobz, const char *uplo, const int *n, float *A, const int *lda, float *w, float *work, const int *lwork, int * info);
dsyev_(const char *jobz, const char *uplo, const int *n, double *A, const int *lda, double *w, double *work, const int *lwork, int * info);
cheev_(const char *jobz, const char *uplo, const int *n, float _Complex *A, const int *lda, float *w, float _Complex *work, const int *lwork, float* rwork, int * info);
zheev_(const char *jobz, const char *uplo, const int *n, double _Complex *A, const int *lda, double *w, double _Complex *work, const int *lwork, double* rwork, int * info);
Fortran Interface:
SSYEV(jobz, uplo, n, a, lda, w, work, lwork, info);
DSYEV(jobz, uplo, n, a, lda, w, work, lwork, info);
CHEEV(jobz, uplo, n, a, lda, w, work, lwork, rwork, info);
ZHEEV(jobz, uplo, n, a, lda, w, work, lwork, rwork, info);
参数
参数 |
类型 |
说明 |
输入/输出 |
---|---|---|---|
jobz |
字符型 |
|
输入 |
uplo |
字符型 |
|
输入 |
n |
整数型 |
矩阵A的维度,大于或等于0。 |
输入 |
a |
|
|
输入,输出 |
lda |
整数型 |
矩阵A的主维,大于或等于max(1, N)。 |
输入 |
w |
|
Info=0时,以升序存储特征值,长度为N。 |
输出 |
work |
|
Info=0时,work(0)返回最优lwork大小。 |
输出 |
lwork |
整数型 |
work数组的长度。 lwork=-1时查询最优work大小,结果保存在work[0]中。且lwork ≥ max(1, 2*n-1)。 |
输入 |
rwork(复数特有) |
|
工作数组,取值max(1, 3*n-1)。 |
输出 |
info |
整数型 |
状态值:
|
输出 |
依赖
#include "klapack.h"
示例
C Interface:
char jobz = 'V'; char uplo = 'L'; int n = 5; int lda = 5; int info = 0; double w[5]; double *work = NULL; double qwork; int lwork = -1; /* * Symmetric A (stored in column-major): * 7.027 8.710 1.015 6.929 7.584 * 8.710 0.839 2.469 3.850 0.559 * 1.015 2.469 1.930 6.761 7.207 * 6.929 3.850 6.761 4.344 4.804 * 7.584 0.559 7.207 4.804 6.177 */ double a[] = {7.027, 8.710, 1.015, 6.929, 7.584, 8.710, 0.839, 2.469, 3.850, 0.559, 1.015, 2.469, 1.930, 6.761, 7.207, 6.929, 3.850, 6.761, 4.344, 4.804, 7.584, 0.559, 7.207, 4.804, 6.177}; /* Query optimal work size */ dsyev_(&jobz, &uplo, &n, a, &lda, w, &qwork, &lwork, &info); if (info != 0) { return ERROR; } lwork = (int)qwork; work = (double *)malloc(sizeof(double) * lwork); /* Calculate eigenvalues and eigenvectors */ dsyev_(&jobz, &uplo, &n, a, &lda, w, work, &lwork, &info); free(work); /* * Output: * Eigenvalues (in w) * -1.770722 -0.845606 -0.203058 -5.712058 3.044889 * Eigenvectors (in a, stored in column-major) * 0.547211 -0.528441 0.339953 -0.172302 -0.531245 * 0.050685 -16.554919 -5.702155 2.261598 15.521155 * -0.456110 0.988485 0.587808 -3.161022 -1.099502 * -0.443428 -1.398420 0.424293 0.800628 0.016423 * -0.541596 -1.770722 -0.845606 -0.203058 -5.712058 */
Fortran Interface:
CHARACTER :: jobz = "V" CHARACTER :: uplo = "L" PARAMETER (n = 5) PARAMETER (lda = 5) INTEGER :: info = 0 REAL(8) :: w(5); REAL(8) :: qwork(1) REAL(8), ALLOCATABLE :: work(:) INTEGER :: lwork = -1 * Symmetric A (stored in column-major): * 7.027 8.710 1.015 6.929 7.584 * 8.710 0.839 2.469 3.850 0.559 * 1.015 2.469 1.930 6.761 7.207 * 6.929 3.850 6.761 4.344 4.804 * 7.584 0.559 7.207 4.804 6.177 REAL(8) :: a(n, n) DATA a / 7.027, 8.710, 1.015, 6.929, 7.584, $ 8.710, 0.839, 2.469, 3.850, 0.559, $ 1.015, 2.469, 1.930, 6.761, 7.207, $ 6.929, 3.850, 6.761, 4.344, 4.804, $ 7.584, 0.559, 7.207, 4.804, 6.177 / * Query optimal work size EXTERNAL DSYEVD CALL DSYEV(jobz, uplo, n, a, lda, w, qwork, lwork, info) IF (info.NE.0) THEN CALL EXIT(1) END IF lwork = INT(qwork(1)) ALLOCATE(work(lwork)) * Calculate eigenvalues and eigenvectors CALL DSYEV(jobz, uplo, n, a, lda, w, work, lwork, info) DEALLOCATE(work); * Output: * Eigenvalues (in w) * -1.770722 -0.845606 -0.203058 -5.712058 3.044889 * Eigenvectors (in a, stored in column-major) * 0.547211 -0.528441 0.339953 -0.172302 -0.531245 * 0.050685 -16.554919 -5.702155 2.261598 15.521155 * -0.456110 0.988485 0.587808 -3.161022 -1.099502 * -0.443428 -1.398420 0.424293 0.800628 0.016423 * -0.541596 -1.770722 -0.845606 -0.203058 -5.71205