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

◆ Zgetri()

Sub Zgetri ( N As  Long,
A() As  Complex,
IPiv() As  Long,
Info As  Long 
)

Inverse of a complex matrix

Purpose
This routine computes the inverse of a matrix using the LU factorization computed by Zgetrf.

This method inverts U and then computes inv(A) by solving the system inv(A)*L = inv(U) for inv(A).
Parameters
[in]NOrder of the matrix A. (N >= 0) (If N = 0, returns without computation)
[in]A()Array A(LA1 - 1, LA2 - 1) (LA1 >= N, LA2 >= N)
[in] The factors L and U from the factorization A = P*L*U as computed by Zgetrf.
[out] If info = 0, the inverse of the original matrix A.
[in]IPiv()Array IPiv(LIPiv - 1) (LIPiv >= N)
Pivot indices from Dgetrf; for 1 <= i <= n, row i of the matrix was interchanged with row IPiv(i-1).
[out]Info= 0: Successful exit
= -1: The argument N had an illegal value. (N < 0)
= -2: The argument A() is invalid.
= -3: The argument IPiv() is invalid.
= i > 0: The i-th diagonal element of U is exactly zero; the matrix is singular and its inverse could not be computed.
Reference
LAPACK
Example Program
Compute the inverse matrix of A, where
( 0.2-0.11i -0.93-0.32i 0.81+0.37i )
A = ( -0.8-0.92i -0.29+0.86i 0.64+0.51i )
( 0.71+0.59i -0.15+0.19i 0.2+0.94i )
Sub Ex_Zgetri()
Const N = 3
Dim A(N - 1, N - 1) As Complex, IPiv(N - 1) As Long
Dim 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)
Call Zgetrf(N, N, A(), IPiv(), Info)
If Info = 0 Then Call Zgetri(N, A(), IPiv(), Info)
Debug.Print "Inv(A) ="
Debug.Print Creal(A(0, 0)), Cimag(A(0, 0)), Creal(A(0, 1)), Cimag(A(0, 1))
Debug.Print Creal(A(0, 2)), Cimag(A(0, 2))
Debug.Print Creal(A(1, 0)), Cimag(A(1, 0)), Creal(A(1, 1)), Cimag(A(1, 1))
Debug.Print Creal(A(1, 2)), Cimag(A(1, 2))
Debug.Print Creal(A(2, 0)), Cimag(A(2, 0)), Creal(A(2, 1)), Cimag(A(2, 1))
Debug.Print Creal(A(2, 2)), Cimag(A(2, 2))
Debug.Print "Info =", Info
End Sub
Example Results
Inv(A) =
-0.201994189100174 -0.220248055307507 -0.368148317320952 0.290272208608198
0.360511523756756 -0.418803146203832
-0.614836963994613 0.455294217428579 6.83276126510658E-02 -0.256899969150471
9.45427369503751E-02 -0.502999571841184
0.47052389723088 9.18669160683443E-02 4.42160986558556E-02 -0.409830677026182
8.10655554407012E-02 -0.424831215613866
Info = 0