XLPack 7.0
XLPack Numerical Library (Excel VBA) Reference Manual
Loading...
Searching...
No Matches

◆ Dhsein()

Sub Dhsein ( Side As  String,
Eigsrc As  String,
Initv As  String,
Selct() As  Boolean,
N As  Long,
H() As  Double,
Wr() As  Double,
Wi() As  Double,
Vl() As  Double,
Vr() As  Double,
Mm As  Long,
M As  Long,
Ifaill() As  Long,
Ifailr() As  Long,
Info As  Long 
)

Eigenvectors of Hessenberg matrix by inverse iteration method

Purpose
This routine uses inverse iteration to find specified right and/or left eigenvectors of a real upper Hessenberg matrix H.

The right eigenvector x and the left eigenvector y of the matrix H corresponding to an eigenvalue w are defined by:
H * x = w * x, y^H * H = w * y^H
where y^H denotes the conjugate transpose of the vector y.
Parameters
[in]Side= "R": Compute right eigenvectors only.
= "L": Compute left eigenvectors only.
= "B": Compute both right and left eigenvectors.
[in]EigsrcSpecifies the source of eigenvalues supplied in (Wr(), Wi()).
= "Q": The eigenvalues were found using dhseqr; thus, if H has zero subdiagonal elements, and so is block-triangular, then the j-th eigenvalue can be assumed to be an eigenvalue of the block containing the j-th row/column. This property allows this routine to perform inverse iteration on just one diagonal block.
= "N": No assumptions are made on the correspondence between eigenvalues and diagonal blocks. In this case, this routine must always perform inverse iteration using the whole matrix H.
[in]Initv= "N": No initial vectors are supplied;
= "U": User-supplied initial vectors are stored in the arrays vl and/or vr.
[in,out]Selct()Array Selct(LSelct - 1) (LSelct >= N)
[in] Specifies the eigenvectors to be computed. To select the real eigenvector corresponding to a real eigenvalue Wr(j), Selct(j) must be set to True. To select the complex eigenvectors corresponding to a complex eigenvalue (Wr(j), Wi(j)), with complex conjugate (Wr(j+1), Wi(j+1)), either Selct(j) or Selct(j+1) or both must be set to True.
[out] If the complex eigenvectors corresponding to complex conjugate eigenvalues are selected, Selct(j) is set to True and Selct(j+1) is set to False.
[in]NOrder of the matrix H. (N >= 0) (If N = 0, returns without computation)
[in]H()Array H(LH1 - 1, LH2 - 1) (LH1 >= N, LH2 >= N)
The upper Hessenberg matrix H.
If a NaN is detected in H(), the routine will return with Info = -7.
[in,out]Wr()Array Wr(LWr - 1) (LWr >= N)
[in]Wi()Array Wi(LWi - 1) (LWi >= N)
[in] The real and imaginary parts of the eigenvalues of H. A complex conjugate pair of eigenvalues must be stored in consecutive elements of Wr() and Wi().
[out] Wr() may have been altered since close eigenvalues are perturbed slightly in searching for independent eigenvectors.
[in,out]Vl()Array Vl(LVl1 - 1, LVl2 - 1) (LVl1 >= N, LVl2 >= MM)
[in] If Initv = "U" and Side = "L" or "B", Vl() must contain starting vectors for the inverse iteration for the left eigenvectors. The starting vector for each eigenvector must be in the same column(s) in which the eigenvector will be stored.
[out] If Side = "L" or "B", the left eigenvectors specified by Selct() will be stored consecutively in the columns of Vl(), in the same order as their eigenvalues. A complex eigenvector corresponding to a complex eigenvalue is stored in two consecutive columns, the first holding the real part and the second the imaginary part.
If Side = "R", Vl() is not referenced.
[in,out]Vr()Array Vr(LVr1 - 1, LVr2 - 1) (LVr1 >= N, LVr2 >= MM)
[in] If Initv = "U" and Side = "R" or "B", Vr() must contain starting vectors for the inverse iteration for the right eigenvectors. The starting vector for each eigenvector must be in the same column(s) in which the eigenvector will be stored.
[out] If Side = "R" or "B", the right eigenvectors specified by Selct() will be stored consecutively in the columns of Vr(), in the same order as their eigenvalues. A complex eigenvector corresponding to a complex eigenvalue is stored in two consecutive columns, the first holding the real part and the second the imaginary part.
If Side = "L", Vr() is not referenced.
[in]MMThe number of columns in the arrays Vl() and/or Vr(). (MM >= M)
[out]MThe number of columns in the arrays Vl() and/or Vr() required to store the eigenvectors. Each selected real eigenvector occupies one column and each selected complex eigenvector occupies two columns.
[out]Ifaill()Array Ifaill(LIfaill - 1) (LIfaill >= MM)
If Side = "L" or "B", Ifaill(i) = j > 0 if the left eigenvector in the i-th column of Vl() (corresponding to the eigenvalue W(j)) failed to converge. Ifaill(i) = 0 if the eigenvector converged satisfactorily. If the i-th and (i+1)th columns of Vl() hold a complex eigenvector, then Ifaill(i) and Ifaill(i+1) are set to the same value.
If Side = "R", Ifaill() is not referenced.
[out]Ifailr()Array Ifailr(LIfailr - 1) (LIfailr >= MM)
If Side = "R" or "B", Ifailr(i) = j > 0 if the right eigenvector in the i-th column of Vr() (corresponding to the eigenvalue W(j)) failed to converge. Ifailr(i) = 0 if the eigenvector converged satisfactorily. If the i-th and (i+1)th columns of Vr() hold a complex eigenvector, then Ifailr(i) and Ifailr(i+1) are set to the same value.
If Side = "L", Ifailr() is not referenced.
[out]Info= 0: Successful exit.
= -1: The argument Side had an illegal value. (Side <> "R", "L" nor "B")
= -2: The argument Eigsrc had an illegal value. (Eigsrc <> "Q" nor "N")
= -3: The argument Initv had an illegal value. (Initv <> "N" nor "U")
= -4: The argument Selct() is invalid.
= -5: The argument N had an illegal value. (N < 0)
= -6: The argument H() is invalid.
= -7: The argument Wr() is invalid.
= -8: The argument Wi() is invalid.
= -9: The argument Vl() is invalid.
= -10: The argument Vr() is invalid.
= -11: The argument MM had an illegal value. (MM < M) = -13: The argument Ifaill() is invalid.
= -14: The argument Ifailr() is invalid.
= i > 0: i is the number of eigenvectors which failed to converge. See Ifaill() and Ifailr() for further details.
Reference
LAPACK
Example Program
Compute all eigenvalues and eigenvectors of the general matrix A, where
( 0.20 -0.11 -0.93 )
A = ( -0.32 0.81 0.37 )
( -0.80 -0.92 -0.29 )
Reduces to Hessenberg form by Dgehrd, then computes eigenvalues by Dhseqr and those eigenvectors by Dhsein and Dormhr.
Sub Ex_Dgehrd_Dhseqr_Dhsein()
Const N = 3
Dim A(N - 1, N - 1) As Double, Tau(N - 2) As Double
Dim H(N - 1, N - 1) As Double, Z() As Double
Dim Wr(N - 1) As Double, Wi(N - 1) As Double, Selct(N - 1) As Boolean
Dim Vl(N - 1, N - 1) As Double, Vr(N - 1, N - 1) As Double, M As Long
Dim Ilo As Long, Ihi As Long, Ifaill(N - 1) As Long, Ifailr(N - 1) As Long
Dim I As Long, J As Long, Info As Long
A(0, 0) = 0.2: A(0, 1) = -0.11: A(0, 2) = -0.93
A(1, 0) = -0.32: A(1, 1) = 0.81: A(1, 2) = 0.37
A(2, 0) = -0.8: A(2, 1) = -0.92: A(2, 2) = -0.29
Ilo = 1: Ihi = N
Call Dgehrd(N, Ilo, Ihi, A(), Tau(), Info)
If Info <> 0 Then
Debug.Print "Error in Dgehrd: Info =", Info
Exit Sub
End If
For I = 0 To N - 1
For J = 0 To N - 1
H(I, J) = A(I, J)
Next
Next
Call Dhseqr("E", "N", N, Ilo, Ihi, H(), Wr(), Wi(), Z(), Info)
If Info <> 0 Then
Debug.Print "Error in Dhseqr: Info =", Info
Exit Sub
End If
For I = 0 To N - 1
Selct(I) = True
Next
Call Dhsein("B", "Q", "N", Selct(), N, A(), Wr(), Wi(), Vl(), Vr(), N, M, Ifaill(), Ifailr(), Info)
If Info <> 0 Then
Debug.Print "Error in Dhsein: Info =", Info
Exit Sub
End If
Call Dormhr("L", "N", N, N, Ilo, Ihi, A(), Tau(), Vr(), Info)
If Info <> 0 Then
Debug.Print "Error in Dormhr: Info =", Info
Exit Sub
End If
Call Dormhr("L", "N", N, N, Ilo, Ihi, A(), Tau(), Vl(), Info)
If Info <> 0 Then
Debug.Print "Error in Dormhr: Info =", Info
Exit Sub
End If
Debug.Print "Eigenvalues (r) =", Wr(0), Wr(1), Wr(2)
Debug.Print "Eigenvalues (i) =", Wi(0), Wi(1), Wi(2)
Debug.Print "Eigenvectors (L) ="
Debug.Print Vl(0, 0), Vl(0, 1), Vl(0, 2)
Debug.Print Vl(1, 0), Vl(1, 1), Vl(1, 2)
Debug.Print Vl(2, 0), Vl(2, 1), Vl(2, 2)
Debug.Print "Eigenvectors (R) ="
Debug.Print Vr(0, 0), Vr(0, 1), Vr(0, 2)
Debug.Print Vr(1, 0), Vr(1, 1), Vr(1, 2)
Debug.Print Vr(2, 0), Vr(2, 1), Vr(2, 2)
Debug.Print "M =", M
End Sub
Sub Dormhr(Side As String, Trans As String, M As Long, N As Long, Ilo As Long, Ihi As Long, A() As Double, Tau() As Double, C() As Double, Info As Long)
Multiplies by a transform matrix to Hessenberg form
Sub Dgehrd(N As Long, Ilo As Long, Ihi As Long, A() As Double, Tau() As Double, Info As Long)
Reduces a real general matrix to upper Hessenberg form
Sub Dhsein(Side As String, Eigsrc As String, Initv As String, Selct() As Boolean, N As Long, H() As Double, Wr() As Double, Wi() As Double, Vl() As Double, Vr() As Double, Mm As Long, M As Long, Ifaill() As Long, Ifailr() As Long, Info As Long)
Eigenvectors of Hessenberg matrix by inverse iteration method
Sub Dhseqr(Job As String, Compz As String, N As Long, Ilo As Long, Ihi As Long, H() As Double, Wr() As Double, Wi() As Double, Z() As Double, Info As Long)
Eigenvalues and Schur factorization of Hessenberg matrix by QR method
Example Results
Eigenvalues (r) = -0.904130023851345 0.812065011925673 0.812065011925673
Eigenvalues (i) = 0 0.48915757543818 -0.48915757543818
Eigenvectors (L) =
-0.780366759827849 0.442486777319186 -0.353989421855349
-0.517119803163016 0.539408759469125 0.533652513982974
-0.870185040161694 -0.337856087926769 0.327926867989764
Eigenvectors (R) =
-0.922812932547959 -0.385121132500322 -0.406438554278919
6.58962255629428E-02 0.64221680239353 -0.221790002576845
-1.10339145165208 -3.62765327766942E-02 0.49628885836462
M = 3