Rate This Document
Findability
Accuracy
Completeness
Readability

?sy(he)ev

Compute all the eigenvalues and eigenvectors of a symmetric or Hermitian matrix.

Interface Definition

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);

Parameters

Parameter

Type

Description

Input/Output

jobz

Character

'N': Computes only eigenvalues.

'V': Computes eigenvalues and eigenvectors.

Input

uplo

Character

'U': Stores the upper triangular part of A.

'L': Stores the lower triangular part of A.

Input

n

Integer

Dimension of matrix A, which is greater than or equal to 0

Input

a

  • A single-precision floating-point array in ssyev
  • A double-precision floating-point array in dsyev
  • A single-precision complex number array in cheev
  • A double-precision complex number array in zheev
  • Saves the symmetric matrix to be factorized before calling.
  • Saves the eigenvectors after calling.

Input/Output

lda

Integer

Leading dimension of matrix A, which is greater than or equal to max(1, N)

Input

w

  • A single-precision floating-point array in ssyevd or cheevd
  • A double-precision floating-point array in dsyevd or zheevd

If info is set to 0, eigenvalues are stored in ascending order. The length is the value of n.

Output

work

  • A single-precision floating-point array in ssyev
  • A double-precision floating-point array in dsyev
  • A single-precision complex number array in cheev
  • A double-precision complex number array in zheev

If info is set to 0, work(0) returns the optimal lwork size.

Output

lwork

Integer

Length of the work array.

If lwork=-1, the optimal work size is queried and the result is saved in work[0]. lwork ≥ max(1, 2*n-1)

Input

rwork (only available for the complex number type)

  • A single-precision floating-point array in ssyevd or cheevd
  • A double-precision floating-point array in dsyevd or zheevd

Work array. The value is max(1, 3*n-1).

Output

info

Integer

Function execution status.

  • 0: The execution is successful.
  • Smaller than 0: If the value of info is -i, the ith parameter is invalid.
  • Greater than 0: An algorithm error occurs.

Output

Dependencies

#include "klapack.h"

Examples

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