DataLab is a compact statistics package aiming at exploratory data analysis. Please visit the DataLab Web site for more information....


EigenDecomposition

Declaration: EigenDecomposition (Data: TDouble2DArray; SortEV: boolean; var EigenVectors: TDouble2DArray; var EigenValues: TDoubleArray): integer;
The function EigenDecomposition calculates the eigenvectors and eigenvalues of the symmetric matrix Data. The results of the eigenanalysis (i.e. the eigenvalues and the eigenvectors) are returned in the variable parameters EigenVectors and EigenValues. If the parameter SortEV is set to TRUE the eigenvectors and eigenvalues are sorted in decreasing order of the eigenvalues.

The function returns the following error codes:

 0 ... everything is OK
-1 ... the matrix Data is not square
-2 ... the Jacobi rotation did not converge
-3 ... routine aborted by user

Hint: EigenDecomposition uses Jacobi rotation to calculate the eigenvectors. Thus it must not be applied to asymmetric matrices.

Example: The eigenvectors are stored rowwise in the array EigenVectors. The following code snippet shows how to calculate the eigenvectors and copy the first and second eigenvector into the one-dimensional arrays Evec1 and Evec2 (assuming that the symmetric matrix CovarMat contains the covariance matrix):

...
var
  CovarMat       : TDouble2DArray;
  EigVec         : TDouble2DArray;
  EigVal         : TDoubleArray;
  Evec1          : TDoubleArray;
  Evec2          : TDoubleArray;
...
errnum := EigenDecomposition (CovarMat, true, Eigvec, EigVal);
CopyArrayRow (EigVec, 0, 0, 0, Evec1);  // first eigenvector (row index 0)
CopyArrayRow (EigVec, 1, 0, 0, Evec2);  // second eigenvector (row index 1)
...