Finds the real and the imaginary parts of the Eigenvalues and the Eigenvectors of the current matrix object.
MatrixObject.Eigen RealValues, ImagValues, RealVectors, ImagVectors
Symmetric matrices have only real Eigenvalues and Eigenvectors, thus in this case ImagValues and ImagVectors parameters are always returned with all their elements set to 0.
Non-symmetric matrices may have either real or complex Eigenvalues and real or complex corresponding Eigenvectors.
If RealVectors and ImagVectors parameters are omitted or not set (set to Nothing), then only Eigenvalues are calculated and Eigen method proceeds faster.
Eigenvectors are returned normalized.
The Eigen method is supported only in Advanced and Advanced II editions of ShortName .
Error 1305 will be returned, if matrix is not square.
Error 1317 will be returned, if internal routines cannot converge to a valid Eigenvalue.
Private Sub MatrixEigen()
Dim A As New Matrix, X As Matrix, B As Matrix, C As Matrix
Dim N As Long, M As Long
Dim Lambda As Double
Dim k As Long
'Declare 2 matrix variables that will hold
'the real and imaginary parts of Eigenvalues
Dim Vr As New Matrix, Vi As New Matrix
'Declare 2 matrix variables that will hold
'the real and imaginary parts of Eigenvectors
Dim Er As New Matrix, Ei As New Matrix
'setting matrix size
N = 3
'initializing matrix to a 4x4 matrix
A.Size N + 1, N + 1
Do
'fill matrix with random values
A.FillRandom
'compute Eigenvalues and Eigenvectors
A.Eigen Vr, Vi, Er, Ei
'Print results
Debug.Print "==============================="
Debug.Print "Matrix ="
Debug.Print A.GetString
Debug.Print "==============================="
Debug.Print "Eigenvalues (real parts)"
Debug.Print Vr.GetString
Debug.Print "Eigenvalues (imaginary parts)"
Debug.Print Vi.GetString
Debug.Print "Eigenvectors (real parts)"
Debug.Print Er.GetString
Debug.Print "Eigenvectors (imaginary parts)"
Debug.Print Ei.GetString
Debug.Print "Verify real Eigenvalues - Eigenvectors"
'now verify real Eigenvalues - Eigenvectors
'check if matrix has a real Eigenvalue
For k = 0 To N
'if imaginary part equals to 0
'then a real Eigenvalue was found
If Vi(k, 0) = 0 Then
'set Lambda to real Eigenvalue
Lambda = Vr(k, 0)
'Verifing this Eigenvalue
'Fisrt set X to corresponding Eigenvector
Set X = Er.ColVector(k)
'form the product A x X
Set B = A.Times(X)
'multiply X by the Eigenvalue (Lambda)
Set C = X.TimesScalar(Lambda)
'now write the results
Debug.Print "Real Eigenvalue = "; Lambda
Debug.Print "Corresponding Eigenvector ="
Debug.Print X.GetString
Debug.Print "A x X ="
Debug.Print B.GetString
Debug.Print "Lambda x X ="
Debug.Print C.GetString
Debug.Print
End If
Next
M = M + 1
Loop Until M >= 2 ' set maximum loops here
End Sub
=============================== Matrix = | 6.000 2.000 8.000 6.000 | | 5.000 4.000 9.000 8.000 | | 7.000 2.000 9.000 7.000 | | 5.000 3.000 0.000 1.000 | =============================== Eigenvalues (real parts) | 20.042 | | 2.264 | | -1.673 | | -0.632 | Eigenvalues (imaginary parts) | 0.000 | | 0.000 | | 0.000 | | 0.000 | Eigenvectors (real parts) | -0.857 -0.427 -0.193 -0.007 | | -1.000 1.000 -0.570 -0.532 | | -0.967 -0.563 -0.423 -0.611 | | -0.382 0.683 1.000 1.000 | Eigenvectors (imaginary parts) | 0.000 0.000 0.000 0.000 | | 0.000 0.000 0.000 0.000 | | 0.000 0.000 0.000 0.000 | | 0.000 0.000 0.000 0.000 | Verify real Eigenvalues - Eigenvectors Real Eigenvalue = 20.0418603740881 Corresponding Eigenvector = | -0.857 | | -1.000 | | -0.967 | | -0.382 | A x X = | -17.167 | | -20.042 | | -19.373 | | -7.665 | Lambda x X = | -17.167 | | -20.042 | | -19.373 | | -7.665 | Real Eigenvalue = 2.26368807936636 Corresponding Eigenvector = | -0.427 | | 1.000 | | -0.563 | | 0.683 | A x X = | -0.967 | | 2.264 | | -1.274 | | 1.547 | Lambda x X = | -0.967 | | 2.264 | | -1.274 | | 1.547 | Real Eigenvalue = -1.67324141554838 Corresponding Eigenvector = | -0.193 | | -0.570 | | -0.423 | | 1.000 | A x X = | 0.323 | | 0.953 | | 0.707 | | -1.673 | Lambda x X = | 0.323 | | 0.953 | | 0.707 | | -1.673 | Real Eigenvalue = -0.63230703790608 Corresponding Eigenvector = | -0.007 | | -0.532 | | -0.611 | | 1.000 | A x X = | 0.005 | | 0.336 | | 0.386 | | -0.632 | Lambda x X = | 0.005 | | 0.336 | | 0.386 | | -0.632 | =============================== Matrix = | 1.000 2.000 10.000 4.000 | | 1.000 0.000 0.000 4.000 | | 5.000 6.000 6.000 6.000 | | 2.000 7.000 5.000 4.000 | =============================== Eigenvalues (real parts) | 15.992 | | -3.796 | | -3.796 | | 2.600 | Eigenvalues (imaginary parts) | 0.000 | | 1.082 | | -1.082 | | 0.000 | Eigenvectors (real parts) | 0.884 -1.000 -1.000 1.000 | | 0.230 0.108 0.108 -0.526 | | 1.000 0.476 0.476 0.502 | | 0.699 -0.051 -0.051 -0.592 | Eigenvectors (imaginary parts) | 0.000 0.027 -0.027 0.000 | | 0.000 0.736 -0.736 0.000 | | 0.000 0.002 -0.002 0.000 | | 0.000 -0.676 0.676 0.000 | Verify real Eigenvalues - Eigenvectors Real Eigenvalue = 15.9924055234203 Corresponding Eigenvector = | 0.884 | | 0.230 | | 1.000 | | 0.699 | A x X = | 14.139 | | 3.679 | | 15.992 | | 11.173 | Lambda x X = | 14.139 | | 3.679 | | 15.992 | | 11.173 | Real Eigenvalue = 2.60021575436832 Corresponding Eigenvector = | 1.000 | | -0.526 | | 0.502 | | -0.592 | A x X = | 2.600 | | -1.367 | | 1.305 | | -1.539 | Lambda x X = | 2.600 | | -1.367 | | 1.305 | | -1.539 |
Applies To: Matrix