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

◆ Zgesvx()

Sub Zgesvx ( Fact As  String,
Trans As  String,
N As  Long,
A() As  Complex,
Af() As  Complex,
IPiv() As  Long,
Equed As  String,
R() As  Double,
C() As  Double,
B() As  Complex,
X() As  Complex,
RCond As  Double,
FErr() As  Double,
BErr() As  Double,
Info As  Long,
Optional Nrhs As  Long = 1,
Optional RPiv As  Double 
)

(Expert driver) Solution to system of linear equations AX = B for a complex matrix

Purpose
This routine uses the LU factorization to computes the solution to a complex system of linear equations
A * X = B, A^T * X = B or A^H * X = B
where A is an n x n matrix and X and B are n x nrhs matrices.
Error bounds on the solution and a condition estimate are also provided.
Description
The following steps are performed:

  1. If Fact = "E", scaling factors are computed to equilibrate the system:
    Trans = "N": diag(R)*A*diag(C)*inv(diag(C))*X = diag(R)*B
    Trans = "T" or "C": (diag(R)*A*diag(C))^T *inv(diag(R))*X = diag(C)*B
    Whether or not the system will be equilibrated depends on the scaling of the matrix A, but if equilibration is used, A is overwritten by diag(R)*A*diag(C) and B by diag(R)*B (if Trans = "N") or diag(C)*B (if Trans = "T" or "C").

  2. If Fact = "N" or "E", the LU decomposition is used to factor the matrix A (after equilibration if Fact = "E") as
    A = P * L * U
    where P is a permutation matrix, L is a unit lower triangular matrix, and U is upper triangular.

  3. If i-th diagonal element of U = 0, so that U is exactly singular, then the routine returns with info = i. Otherwise, the factored form of A is used to estimate the condition number of the matrix A. If the reciprocal of the condition number is less than machine precision, info = n+1 is returned as a warning, but the routine still goes on to solve for X and compute error bounds as described below.

  4. The system of equations is solved for X using the factored form of A.

  5. Iterative refinement is applied to improve the computed solution matrix and calculate error bounds and backward error estimates for it.

  6. If equilibration was used, the matrix X is premultiplied by diag(C) (if Trans = "N") or diag(R) (if Trans = "T" or "C") so that it solves the original system before equilibration.
Parameters
[in]FactSpecifies whether or not the factored form of the matrix A is supplied on entry, and if not, whether the matrix A should be equilibrated before it is factored.
= "F": Af() and IPiv() contain the factored form of A. If equed is not "N", the matrix A has been equilibrated with scaling factors given by R() and C(). A(), Af() and IPiv() are not modified.
= "N": The matrix A will be copied to Af() and factored.
= "E": The matrix A will be equilibrated if necessary, then copied to Af() and factored.
[in]TransSpecifies the form of the system of equations:
= "N": A * X = B. (no transpose)
= "T": A^T * X = B. (transpose)
= "C": A^H * X = B. (conjugate transpose)
[in]NNumber of linear equations, i.e., order of the matrix A. (N >= 0) (If N = 0, returns without computation)
[in,out]A()Array A(LA1 - 1, LA2 - 1) (LA1 >= N, LA2 >= N)
[in] N x N matrix A. If Fact = "F" and Equed is not "N", then A must have been equilibrated by the scaling factors in R() and/or C().
[out] A is not modified if Fact = "F" or "N", or if Fact = "E" and Equed = "N" on exit.
  If Fact = "E" and Equed <> "N" on exit, A is scaled as follows:
    equed = "R": A = diag(R)*A,
    equed = "C": A = A*diag(C), or
    equed = "B": A = diag(R)*A*diag(C).
[in,out]Af()Array Af(LAf1 - 1, LAf2 - 1) (LAf1 >= N, LAf2 >= N)
[in] If Fact = "F", the factors L and U from the factorization A = P*L*U as computed by Zgetrf. If Equed <> "N", Af() is the factored form of the equilibrated matrix A.
[out] If Fact = "N", the factors L and U from the factorization A = P*L*U of the original matrix A.
  If Fact = "E", the factors L and U from the factorization A = P*L*U of the equilibrated matrix A (see the description of A for the form of the equilibrated matrix).
[out]IPiv()Array IPiv(LIPiv - 1) (LIPiv >= N)
[in] If Fact = "F", the pivot indices from the factorization A = P*L*U as computed by Zgetrf; row i of the matrix was interchanged with row IPiv(i-1).
[out] If Fact = "N", the pivot indices from the factorization A = P*L*U of the original matrix A.
  If Fact = "E", the pivot indices from the factorization A = P*L*U of the equilibrated matrix A.
[in,out]EquedSpecifies the form of equilibration that was done.
= "N": No equilibration.
= "R": Row equilibration, i.e., A has been premultiplied by diag(R).
= "C": Column equilibration, i.e., A has been postmultiplied by diag(C).
= "B": Both row and column equilibration, i.e., A has been replaced by diag(R)*A*diag(C).
[in] If Fact = "F", the form of equilibration of the supplied matrix in Af().
[out] If Fact <> "F", the form of equilibration that was done ("N", "R", "C" or "B"). If Fact = "N", Equed is always "N".
[in,out]R()Array R(LR - 1) (LR >= N)
The row scale factors diag(R) for A. If Equed = "R" or "B", A is multiplied on the left by diag(R). If Fact = "N", R() is not accessed.
[in] If Fact = "F", the row scale factors for the supplied matrix in Af(). (Each element must be > 0)
[out] If Fact <> "F", the resulted row scale factors for A.
[in,out]C()Array C(LC - 1) (LC >= N)
The column scale factors diag(C) for A. If Equed = "C" or "B", A is multiplied on the right by diag(C). If Fact = "N", C()is not accessed.
[in] If Fact = "F", the column scale factors for the supplied matrix in Af(). (Each element must be > 0)
[out] If Fact <> "F", the resulted column scale factors for A.
[in,out]B()Array B(LB1 - 1, LB2 - 1) (LB1 >= max(1, N), LB2 >= Nrhs) (2D array) or B(LB - 1) (LB >= max(1, N), Nrhs = 1) (1D array)
[in] N x Nrhs right hand side matrix B.
[out] If Equed = "N", B() is not modified.
  If Trans = "N" and Equed = "R" or "B", B() is overwritten by diag(R)*B.
  If Trans = "T" or "C" and Equed = "C" or "B", B() is overwritten by diag(C)*B.
[out]X()Array X(LX1 - 1, LX2 - 1) (LX1 >= max(1, N), LX2 >= Nrhs) (2D array) or X(LX - 1) (LX >= max(1, N), Nrhs = 1) (1D array)
If Info = 0 or Info = N+1, the N x Nrhs solution matrix X to the original system of equations. Note that A and B are modified on exit if Equed <> "N", and the solution to the equilibrated system is inv(diag(C))*X if Trans = "N" and Equed = "C" or "B", or inv(diag(R))*X if Trans = "T" or "C" and Equed = "R" or "B".
[out]RCondThe estimate of the reciprocal condition number of the matrix A after equilibration (if done). If RCond is less than the machine precision (in particular, if RCond = 0), the matrix is singular to working precision. This condition is indicated by a return code of Info > 0.
[out]FErr()Array FErr(LFErr - 1) (LFErr >= Nrhs)
The estimated forward error bound for each solution vector X(j) (the j-th column of the solution matrix X). If Xtrue is the true solution corresponding to X(j), FErr(j-1) is an estimated upper bound for the magnitude of the largest element in (X(j) - Xtrue) divided by the magnitude of the largest element in X(j). The estimate is as reliable as the estimate for rcond, and is almost always a slight overestimate of the true error.
[out]BErr()Array BErr(LBErr - 1) (LBErr >= Nrhs)
The componentwise relative backward error of each solution vector X(j) (i.e., the smallest relative change in any element of A or B that makes X(j) an exact solution).
[out]Info= 0: Successful exit.
= -1: The argument Fact had an illegal value. (Fact <> "F", "N" nor "E")
= -2: The argument Trans had an illegal value. (Trans <> "N", "T" nor "C")
= -3: The argument N had an illegal value. (N < 0)
= -4: The argument A() is invalid.
= -5: The argument Af() is invalid.
= -6: The argument IPiv() is invalid.
= -7: The argument Equed had an illegal value. (Fact = "F" and Equed <> "N", "R", "C" nor "B")
= -8: The argument R() is invalid, or had an illegal value. (R(i) <= 0 when Fact = "F" and Equed = "R" or "B")
= -9: The argument C() is invalid, or had an illegal value. (C(i) <= 0 when Fact = "F" and Equed = "C" or "B")
= -10: The argument B() is invalid.
= -11: The argument X() is invalid.
= -13: The argument FErr() is invalid.
= -14: The argument BErr() is invalid.
= -16: The argument Nrhs had an illegal value. (Nrhs < 0)
= i (0 < i <= N): The i-th diagonal element of the factor U is exactly zero. The factorization has been completed, but the factor U is exactly singular, so the solution and error bounds could not be computed. RCond = 0 is returned.
= N+1: U is nonsingular, but RCond is less than machine precision, meaning that the matrix is singular to working precision. Nevertheless, the solution and error bounds are computed because there are a number of situations where the computed solution can be more accurate than the value of RCond would suggest.
[in]Nrhs(Optional)
Number of right hand sides, i.e., number of columns of the matrix B. (Nrhs >= 0) (If Nrhs = 0, returns without computation) (default = 1)
[out]RPiv(Optional)
The reciprocal pivot growth factor norm(A)/norm(U). The "max absolute element" norm is used. If this is much less than 1, then the stability of the LU factorization of the (equilibrated) matrix A could be poor. This also means that the solution X, condition estimator rcond, and forward error bound ferr could be unreliable. If factorization fails with 0 < Info <= N, then the reciprocal pivot growth factor is for the leading Info columns of A.
Reference
LAPACK
Example Program
Solve the system of linear equations Ax = B and estimate the reciprocal of the condition number (RCond) 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 )
( -0.5853-0.9457i )
B = ( -2.1697-1.0006i )
( 0.0116-0.5094i )
Sub Ex_Zgesvx()
Const N = 3
Dim A(N - 1, N - 1) As Complex, Af(N - 1, N - 1) As Complex, IPiv(N - 1) As Long
Dim B(N - 1) As Complex, X(N - 1) As Complex
Dim R(N - 1) As Double, C(N - 1) As Double, Equed As String
Dim FErr(0) As Double, BErr(0) As Double
Dim RCond As Double, 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)
B(0) = Cmplx(-0.5853, -0.9457): B(1) = Cmplx(-2.1697, -1.0006): B(2) = Cmplx(0.0116, -0.5094)
Call Zgesvx("N", "N", N, A(), Af(), IPiv(), Equed, R(), C(), B(), X(), RCond, FErr(), BErr(), Info)
Debug.Print "X =", Creal(X(0)), Cimag(X(0)), Creal(X(1)), Cimag(X(1)), Creal(X(2)), Cimag(X(2))
Debug.Print "RCond =", RCond, "Equed = ", Equed
Debug.Print "Info =", Info
End Sub
Example Results
X = 0.79 -0.13 0.13 0.75 -0.91 0.3
RCond = 0.250214147937285 Equed = N
Info = 0