XLPack 6.1
Excel VBA Numerical Library Reference Manual
Loading...
Searching...
No Matches

◆ Zhsein()

Sub Zhsein ( Side As  String,
Eigsrc As  String,
Initv As  String,
Selct() As  Boolean,
N As  Long,
H() As  Complex,
W() As  Complex,
Vl() As  Complex,
Vr() As  Complex,
Mm As  Long,
M As  Long,
Ifaill() As  Long,
Ifailr() As  Long,
Info As  Long 
)

Eigenvectors of complex Hessenberg matrix by inverse iteration method

Purpose
This routine uses inverse iteration to find specified right and/or left eigenvectors of a complex 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 Zhseqr; 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]Selct()Array Selct(LSelct - 1) (LSelct >= N)
Specifies the eigenvectors to be computed. To select the eigenvector corresponding to the eigenvalue W(j), Selct(j) must be set to True.
[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]W()Array W(LW - 1) (LW >= N)
[in] The eigenvalues of H.
[out] The real part of W() 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.
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.
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 (= the number of True elements in Selct()).
[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 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 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 W() is invalid.
= -8: The argument Vl() is invalid.
= -9: The argument Vr() is invalid.
= -10: The argument MM had an illegal value. (MM < M) = -12: The argument Ifaill() is invalid.
= -13: 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.11i -0.93-0.32i 0.81+0.37i )
A = ( -0.80-0.92i -0.29+0.86i 0.64+0.51i )
( 0.71+0.59i -0.15+0.19i 0.20+0.94i )
Reduces to Hessenberg form by Zgehrd, then computes eigenvalues by Zhseqr and those eigenvectors by Zhsein and Zunmhr.
Sub Ex_Zgehrd_Zhseqr_Zhsein()
Const N = 3
Dim A(N - 1, N - 1) As Complex, Tau(N - 2) As Complex, H(N - 1, N - 1) As Complex
Dim W(N - 1) As Complex, Z() As Complex, Selct(N - 1) As Boolean
Dim Vl(N - 1, N - 1) As Complex, Vr(N - 1, N - 1) As Complex, 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) = Cmplx(0.2, -0.11): A(0, 1) = Cmplx(-0.93, -0.32): A(0, 2) = Cmplx(0.81, 0.37)
A(1, 0) = Cmplx(-0.8, -0.92): A(1, 1) = Cmplx(-0.29, 0.86): A(1, 2) = Cmplx(0.64, 0.51)
A(2, 0) = Cmplx(0.71, 0.59): A(2, 1) = Cmplx(-0.15, 0.19): A(2, 2) = Cmplx(0.2, 0.94)
Ilo = 1: Ihi = N
Call Zgehrd(N, Ilo, Ihi, A(), Tau(), Info)
If Info <> 0 Then
Debug.Print "Error in Zgehrd: 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 Zhseqr("E", "N", N, Ilo, Ihi, H(), W(), Z(), Info)
If Info <> 0 Then
Debug.Print "Error in Zhseqr: Info =", Info
Exit Sub
End If
For I = 0 To N - 1
Selct(I) = True
Next
Call Zhsein("B", "Q", "N", Selct(), N, A(), W(), Vl(), Vr(), N, M, Ifaill(), Ifailr(), Info)
If Info <> 0 Then
Debug.Print "Error in Zhsein: Info =", Info
Exit Sub
End If
Call Zunmhr("L", "N", N, N, Ilo, Ihi, A(), Tau(), Vr(), Info)
If Info <> 0 Then
Debug.Print "Error in Zunmhr: Info =", Info
Exit Sub
End If
Call Zunmhr("L", "N", N, N, Ilo, Ihi, A(), Tau(), Vl(), Info)
If Info <> 0 Then
Debug.Print "Error in Zunmhr: Info =", Info
Exit Sub
End If
Debug.Print "Eigenvalues ="
Debug.Print Creal(W(0)), Cimag(W(0)), Creal(W(1)), Cimag(W(1))
Debug.Print Creal(W(2)), Cimag(W(2))
Debug.Print "Eigenvectors (L) ="
Debug.Print Creal(Vl(0, 0)), Cimag(Vl(0, 0)), Creal(Vl(0, 1)), Cimag(Vl(0, 1))
Debug.Print Creal(Vl(1, 0)), Cimag(Vl(1, 0)), Creal(Vl(1, 1)), Cimag(Vl(1, 1))
Debug.Print Creal(Vl(2, 0)), Cimag(Vl(2, 0)), Creal(Vl(2, 1)), Cimag(Vl(2, 1))
Debug.Print Creal(Vl(0, 2)), Cimag(Vl(0, 2))
Debug.Print Creal(Vl(1, 2)), Cimag(Vl(1, 2))
Debug.Print Creal(Vl(2, 2)), Cimag(Vl(2, 2))
Debug.Print "Eigenvectors (R) ="
Debug.Print Creal(Vr(0, 0)), Cimag(Vr(0, 0)), Creal(Vr(0, 1)), Cimag(Vr(0, 1))
Debug.Print Creal(Vr(1, 0)), Cimag(Vr(1, 0)), Creal(Vr(1, 1)), Cimag(Vr(1, 1))
Debug.Print Creal(Vr(2, 0)), Cimag(Vr(2, 0)), Creal(Vr(2, 1)), Cimag(Vr(2, 1))
Debug.Print Creal(Vr(0, 2)), Cimag(Vr(0, 2))
Debug.Print Creal(Vr(1, 2)), Cimag(Vr(1, 2))
Debug.Print Creal(Vr(2, 2)), Cimag(Vr(2, 2))
Debug.Print "M =", M
End Sub
Example Results
Eigenvalues =
-1.15894122423918 -0.50662892448174 1.05593587167591 0.900255855387815
0.21300535256327 1.29637306909393
Eigenvectors (L) =
0 -0.871083495245762 0.2 -0.8
0.267351466048342 -0.480647278057965 -0.03692440974696 0.616773162002434
-0.285413896331544 0.542078734362481 0.166244018883372 -0.368066071419648
-2.22091099794888E-02 0.344241204682076
7.27399270176405E-02 -0.5924933721717
0.347217078108291 -0.4230226508624
Eigenvectors (R) =
0.690958738203183 -0.309041261796817 -0.507806593830091 0.492193406169909
0.634809967097297 -0.421369311149223 0.229049609768182 -0.190619676572438
-0.363524659234702 0.113190794408639 -0.763294421913407 0.107049283139747
-0.111157316336775 -2.52863433046769E-02
-0.481933704163733 0.142931109108698
-0.552705878022003 3.27787741584283E-02
M = 3