Rate This Document
Findability
Accuracy
Completeness
Readability

?sy(he)gv

Compute all the eigenvalues and eigenvectors (optional) of a generalized eigenvalue problem.

Matrices A and B are symmetric (Hermitian), and matrix B is also positive-definite.

Interface Definition

C Interface:

dsygv_(const int *itype, const char *jobz, const char *uplo, const int *n, double *a, const int *lda, double *b, const int *ldb, double *w, double *work, const int *lwork, int *info);

ssygv_(const int *itype, const char *jobz, const char *uplo, const int *n, float *a, const int *lda, float *b, const int *ldb, float *w, float *work, const int *lwork, int *info);

chegv_(const int *itype, const char *jobz, const char *uplo, const int *n, kml_complex_float *a, const int *lda, kml_complex_float *b, const int *ldb, float *w, kml_complex_float *work, const int *lwork,

float *rwork, int *info);

zhegv_(const int *itype, const char *jobz, const char *uplo, const int *n, kml_complex_double *a, const int *lda, kml_complex_double *b, const int *ldb, double *w, kml_complex_double *work, const int *lwork,

double *rwork, int *info);

Fortran Interface:

DSYGV(ITYPE, JOBZ, UPLO, N, A, LDA, B, LDB, W, WORK, LWORK, INFO);

SSYGV(ITYPE, JOBZ, UPLO, N, A, LDA, B, LDB, W, WORK, LWORK, INFO);

CHEGV(ITYPE, JOBZ, UPLO, N, A, LDA, B, LDB, W, WORK, LWORK, RWORK, INFO);

ZHEGV(ITYPE, JOBZ, UPLO, N, A, LDA, B, LDB, W, WORK, LWORK, RWORK, INFO);

Parameters

Parameter

Type

Description

Input/Output

itype

Integer

Problem type to solve.

  • 1: A*x = lambda*B*x
  • 2: A*B*x = (lambda)*x
  • 3: B*A*x = (lambda)*x

Input

jobz

Character

  • N: computes only eigenvalues.
  • V: computes eigenvalues and eigenvectors.

Input

uplo

Character

  • U: stores the upper triangular part of matrix A.
  • L: stores the lower triangular part of matrix A.

Input

n

Integer

Dimensions of matrices A and B.

Input

a

  • A single-precision floating-point array for ssygv
  • A double-precision floating-point array for dsygv
  • A single-precision complex array for chegv
  • A double-precision complex array for zhegv

Matrix A.

Input/Output

lda

Integer

Leading dimension of matrix A.

Input

b

  • A single-precision floating-point array for ssygv
  • A double-precision floating-point array for dsygv
  • A single-precision complex array for chegv
  • A double-precision complex array for zhegv

Matrix B.

Input/Output

ldb

Integer

Leading dimension of matrix B.

Input

w

Single/Double precision

Array of length n, storing the obtained eigenvalues (in ascending order).

Output

work

Single/Double precision

If info = 0, work(0) returns the optimal lwork.

Output

lwork

Integer

Length of the work array.

lwork ≥ max(1, 2*n-1).

Input

rwork (only for complex types)

  • A single-precision complex array for chegv
  • A double-precision complex array for zhegv

Work array, used for temporary data storage.

Output

info

Integer

Function execution status.

0: The execution is successful.

Smaller than 0: The value of the -info-th parameter is invalid.

Greater than 0: An algorithm error occurs.

Output

Dependencies

#include "klapack.h"

Examples

C Interface:
    int itype = 1;
    char jobz = 'V';
    char uplo = 'L';
    int n = 5;
    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};
    int lda = 5;
    double b[] = {2.345678,1.234567,0.987654,1.456789,0.876543,
                1.234567,2.345678,1.123456,0.987654,1.234567,
                0.987654,1.123456,2.345678,1.234567,0.987654,
                1.456789,0.987654,1.234567,2.345678,1.123456,
                0.876543,1.234567,0.987654,1.123456,2.345678};
    int ldb = 5;
    double w[5];
    double work[15];
    int lwork = 15;
    int info = 0;

    dsygv_(&itype, &jobz, &uplo, &n, a, &lda, b, &ldb, w, work, &lwork, &info);

    /* 
     * Output: 
     * Eigenvalues (in w) 
     *  -8.726204 -2.319727 1.043130 4.411714 4.668052 
     * Eigenvectors (in a) 
     *   0.604055 -0.456650 0.512079 -0.505769 -0.177986
     *   0.174314 -0.523003 -0.357093 0.517106 -0.028092 
     *   -0.277558 0.232180 0.310527 0.581010 -0.538289 
     *   0.541974 0.126215 -0.182883 -0.010722 0.210494 
     *   -0.205335 -0.456850 0.389506 0.070554 0.553286
     */

Fortran Interface:

INTEGER :: itype = 1
CHARACTER :: jobz = "V"
CHARACTER :: uplo = "L"
PARAMETER (n = 5)
PARAMETER (lda = 5)
PARAMETER (ldb = 5)
PARAMETER (lwork = 15)
REAL(8) :: a(lda, n)
REAL(8) :: w(n)
REAL(8) :: work(lwork)
INTEGER :: info = 0

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 /
DATA b / 2.345678,1.234567,0.987654,1.456789,0.876543,
         1.234567,2.345678,1.123456,0.987654,1.234567,
         0.987654,1.123456,2.345678,1.234567,0.987654,
         1.456789,0.987654,1.234567,2.345678,1.123456,
         0.876543,1.234567,0.987654,1.123456,2.345678 /

EXTERNAL DSYGV
CALL DSYGV(itype, jobz, uplo, n, a, lda, b, ldb, w, work, lwork, info)