This routine is written in the IDL language. Its source code can be found in the file eigenql.pro in the lib subdirectory of the IDL distribution.
Note: If you are working with complex inputs, use the LA_EIGENQL function instead.
; Define an n-by-n real, symmetric array:
A = [[ 5.0, 4.0, 0.0, -3.0], $
[ 4.0, 5.0, 0.0, -3.0], $
[ 0.0, 0.0, 5.0, -3.0], $
[-3.0, -3.0, -3.0, 5.0]]
; Compute the eigenvalues and eigenvectors:
eigenvalues = EIGENQL(A, EIGENVECTORS = evecs, $
RESIDUAL = residual)
;Print the eigenvalues and eigenvectors:
PRINT, 'Eigenvalues: '
PRINT, 'Eigenvectors: '
12.0915 6.18662 1.00000 0.721870
-0.554531 -0.554531 -0.241745 0.571446
-0.342981 -0.342981 0.813186 -0.321646
0.707107 -0.707107 -6.13503e-008-6.46503e-008
0.273605 0.273605 0.529422 0.754979
The accuracy of each eigenvalue/eigenvector (λ/x) pair may be checked by printing the residual array:
The RESIDUAL array has the same dimensions as the input array and the same type as the result. The residuals are contained in the rows of the RESIDUAL array. All residual values should be floating-point zeros.
This function returns an n-element vector containing the eigenvalues.
An n-by-n symmetric single- or double-precision floating-point array.
Set this keyword to sort the eigenvalues by their absolute value (their magnitude) rather than by their signed value.
Set this keyword to return eigenvalues in ascending order (smallest to largest). If not set or set to zero, eigenvalues are returned in descending order (largest to smallest). The eigenvectors are correspondingly reordered.
Set this keyword to force the computation to be done in double-precision arithmetic.
Set this keyword equal to a named variable that will contain the computed eigenvectors in an n-by-n array. The ith row of the returned array contains the eigenvector corresponding to the ith eigenvalue. If no variable is supplied, the array will not be computed.
Set this keyword to use the input array for internal storage and to overwrite its previous contents.
Use this keyword to specify a named variable that will contain the residuals for each eigenvalue/eigenvector (λ/x) pair. The residual is based on the definition Ax – (λ)x = 0 and is an array of the same size as A and the same type as Result. The rows of this array correspond to the residuals for each eigenvalue/eigenvector pair.
Note: If the OVERWRITE keyword is set, the RESIDUAL keyword has no effect.