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

◆ Dgetri()

Sub Dgetri ( N As  Long,
A() As  Double,
IPiv() As  Long,
Info As  Long 
)

Inverse of a general matrix

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

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 Dgetrf.
[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.11 -0.93 )
A = ( -0.32 0.81 0.37 )
( -0.8 -0.92 -0.29 )
Sub Ex_Dgetri()
Const N = 3
Dim A(N - 1, N - 1) As Double, IPiv(N - 1) As Long
Dim 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
Call Dgetrf(N, N, A(), IPiv(), Info)
If Info = 0 Then Call Dgetri(N, A(), IPiv(), Info)
Debug.Print "Inv(A) ="
Debug.Print A(0, 0), A(0, 1), A(0, 2)
Debug.Print A(1, 0), A(1, 1), A(1, 2)
Debug.Print A(2, 0), A(2, 1), A(2, 2)
Debug.Print "Info =", Info
End Sub
Sub Dgetrf(M As Long, N As Long, A() As Double, IPiv() As Long, Info As Long)
LU factorization of a general matrix
Sub Dgetri(N As Long, A() As Double, IPiv() As Long, Info As Long)
Inverse of a general matrix
Example Results
Inv(A) =
-0.129835926770076 -1.01370476663992 -0.876977075036551
0.478485386997209 0.986999177910909 -0.275178324415061
-1.1597855676599 -0.334742863331381 -0.156049246582423
Info = 0