|
◆ Zgbsvx()
Sub Zgbsvx |
( |
Fact As |
String, |
|
|
Trans As |
String, |
|
|
N As |
Long, |
|
|
Kl As |
Long, |
|
|
Ku As |
Long, |
|
|
Ab() As |
Complex, |
|
|
Afb() 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 band matrix
- Purpose
- This routine uses the LU factorization to computes the solution to a complex system of linear equations where A is a band matrix of order n with kl sub-diagonals and ku super-diagonals, 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 by this subroutine:
- 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").
- If Fact = "N" or "E", the LU decomposition is used to factor the matrix A (after equilibration if Fact = "E") as where L is a product of permutation and unit lower triangular matrices with kl sub-diagonals, and U is upper triangular with kl+ku super-diagonals.
- 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.
- The system of equations is solved for X using the factored form of A.
- Iterative refinement is applied to improve the computed solution matrix and calculate error bounds and backward error estimates for it.
- 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] | Fact | Specifies 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": Afb() 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(), Afb() and IPiv() are not modified.
= "N": The matrix A will be copied to Afb() and factored.
= "E": The matrix A will be equilibrated if necessary, then copied to Afb() and factored. |
[in] | Trans | Specifies 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] | N | Number of linear equations, i.e., order of the matrix A. (N >= 0) (If N = 0, returns without computation) |
[in] | Kl | Number of subdiagonals within the band of A (Kl >= 0) |
[in] | Ku | Number of superdiagonals within the band of A (Ku >= 0) |
[in,out] | Ab() | Array Ab(LAb1 - 1, LAb2 - 1) (LAb1 >= Kl + Ku + 1, LAb2 >= N)
[in] Matrix A in band matrix form, in rows 1 to Kl+Ku+1. If Fact = "F" and Equed <> "N", then A must have been equilibrated by the scaling factors in R() and/or C().
[out] 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": diag(R)*A,
Equed = "C": A*diag(C), or
Equed = "B": diag(R)*A*diag(C). |
[in,out] | Afb() | Array Afb(LAfb1 - 1, LAfb2 - 1) (LAfb1 >= 2Kl + Ku + 1, LAfb2 >= N)
[in] If Fact = "F", details of the LU factorization of the band matrix A, as computed by Dgbtrf. U is stored as an upper triangular band matrix with Kl+Ku super-diagonals in rows 1 to Kl+Ku+1, and the multipliers used during the factorization are stored in rows Kl+Ku+2 to 2*Kl+Ku+1. If Equed <> "N", then Afb() is the factored form of the equilibrated matrix A.
[out] If Fact = "N", returns details of the LU factorization of A.
If Fact = "E", returns details of the LU factorization of the equilibrated matrix A (see the description of Ab() 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 = L*U as computed by Dgbtrf; row i of the matrix was interchanged with row IPiv(i-1).
[out] If Fact = "N", the pivot indices from the factorization A = L*U of the original matrix A.
If Fact = "E", the pivot indices from the factorization A = L*U of the equilibrated matrix A. |
[in,out] | Equed | Specifies 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 Afb().
[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 Afb(). (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 Afb(). (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] | RCond | The 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 Kl had an illegal value. (Kl < 0)
= -5: The argument Ku had an illegal value. (Ku < 0)
= -6: The argument Ab() is invalid.
= -7: The argument Afb() is invalid.
= -8: The argument IPiv() is invalid.
= -9: The argument Equed had an illegal value. (Fact = "F" and Equed <> "N", "R", "C" nor "B")
= -10: The argument R() is invalid, or had an illegal value. (R(i) <= 0 when Fact = "F" and Equed = "R" or "B")
= -11: The argument C() is invalid, or had an illegal value. (C(i) <= 0 when Fact = "F" and Equed = "C" or "B")
= -12: The argument B() is invalid.
= -13: The argument X() is invalid.
= -15: The argument FErr() is invalid.
= -16: The argument BErr() is invalid.
= -18: 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.81+0.37i 0.20-0.11i 0 )
A = ( 0.64+0.51i -0.80-0.92i -0.93-0.32i )
( 0 0.71+0.59i -0.29+0.86i )
( -0.0484+0.2644i )
B = ( -0.2644-1.0228i )
( -0.5299+1.5025i )
Sub Ex_Zgbsvx()
Const N = 3, Kl = 1, Ku = 1
Dim Ab(Kl + Ku, N - 1) As Complex, Afb(2 * Kl + Ku, 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
Ab(0, 1) = Cmplx(0.2, -0.11): Ab(0, 2) = Cmplx(-0.93, -0.32)
Ab(1, 0) = Cmplx(0.81, 0.37): Ab(1, 1) = Cmplx(-0.8, -0.92): Ab(1, 2) = Cmplx(-0.29, 0.86)
Ab(2, 0) = Cmplx(0.64, 0.51): Ab(2, 1) = Cmplx(0.71, 0.59)
B(0) = Cmplx(-0.0484, 0.2644): B(1) = Cmplx(-0.2644, -1.0228): B(2) = Cmplx(-0.5299, 1.5025)
Call Zgbsvx("N", "N", N, Kl, Ku, Ab(), Afb(), IPiv(), Equed, R(), C(), B(), X(), RCond, FErr(), BErr(), Info)
Debug.Print "X =",
Debug.Print 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.15 0.19 0.2 0.94 0.79 -0.13
RCond = 0.187722560135325 Equed = N
Info = 0
|