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

◆ Dspsvx()

Sub Dspsvx ( Fact As  String,
Uplo As  String,
N As  Long,
Ap() As  Double,
Afp() As  Double,
IPiv() As  Long,
B() As  Double,
X() As  Double,
RCond As  Double,
FErr() As  Double,
BErr() As  Double,
Info As  Long,
Optional Nrhs As  Long = 1 
)

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

Purpose
This routine uses the diagonal pivoting factorization to computes the solution to a real system of linear equations
A * X = B
where A is an n x n symmetric 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 = "N", the diagonal pivoting method is used to factor A. The form of the factorization is
    A = U * D * U^T, if Uplo = "U", or
    A = L * D * L^T, if Uplo = "L",
    where U (or L) is a product of permutation and unit upper (lower) triangular matrices, and D is symmetric and block diagonal with 1 x 1 and 2 x 2 diagonal blocks.

  2. If some i-th diagonal element of D = 0, so that D 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.

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

  4. Iterative refinement is applied to improve the computed solution matrix and calculate error bounds and backward error estimates for it.
Parameters
[in]FactSpecifies whether or not the factored form of A has been supplied on entry.
= "F": Af() and IPiv() contain the factored form of A. Af() and IPiv() will not be modified.
= "N": The matrix A will be copied to Af() and factored.
[in]Uplo= "U": Upper triangle of A is stored.
= "L": Lower triangle of A is stored.
[in]NNumber of linear equations, i.e., order of the matrix A. (N >= 0) (If N = 0, returns without computation)
[in]Ap()Array Ap(LAp - 1) (LAp >= N(N + 1)/2)
N x N symmetric matrix A in packed form. The upper or lower part is to be stored in accordance with Uplo.
[in,out]Afp()Array Afp(LAfp - 1) (LAfp >= N(N + 1)/2)
[in] If Fact = "F", the block diagonal matrix D and the multipliers used to obtain the factor U or L from the factorization A = U*D*U^T or A = L*D*L^T as computed by Dsptrf, to be stored as a packed triangular matrix in the same storage format as Ap().
[out] If Fact = "N", the block diagonal matrix D and the multipliers used to obtain the factor U or L from the factorization A = U*D*U^T or A = L*D*L^T as computed by Dsptrf, stored as a packed triangular matrix in the same storage format as Ap().
[in,out]IPiv()Array IPiv(LIPiv - 1) (LIPiv >= N)
[in] If Fact = "F", details of the interchanges and the block structure of D, as determined by Dsptrf, are to be stored.
  If IPiv(k-1) > 0, then rows and columns k and IPiv(k-1) were interchanged, and k-th diagonal of D is a 1 x 1 diagonal block. If Uplo = "U" and IPiv(k-1) = IPiv(k-2) < 0, then rows and columns k-1 and -IPiv(k-1) were interchanged and (k-1)-th diagonal of D is a 2 x 2 diagonal block. If Uplo = "L" and IPiv(k-1) = IPiv(k) < 0, then rows and columns k+1 and -IPiv(k-1) were interchanged and k-th diagonal of D is a 2 x 2 diagonal block. [out] If Fact = "N", details of the interchanges and the block structure of D, as determined by Dsptrf, are returned.
[in]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)
N x Nrhs matrix of right hand side matrix 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, N x Nrhs solution matrix X.
[out]RCondThe estimate of the reciprocal condition number of the matrix A. 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 Uplo had an illegal value. (Uplo <> "U" nor "L")
= -3: The argument N had an illegal value. (N < 0)
= -4: The argument Ap() is invalid.
= -5: The argument Afp() is invalid.
= -6: The argument IPiv() is invalid.
= -7: The argument B() is invalid.
= -8: The argument X() is invalid.
= -10: The argument FErr() is invalid.
= -11: The argument BErr() is invalid.
= -13: The argument Nrhs had an illegal value. (Nrhs < 0)
= i (0 < i <= N): The i-th element of the factor D is exactly zero. The factorization has been completed, but the factor D is exactly singular, so the solution and error bounds could not be computed. RCond = 0 is returned.
= N+1: D 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)
Reference
LAPACK
Example Program
Solve the system of linear equations Ax = B and estimate the reciprocal of the condition number (RCond) of A, where
( 2.2 -0.11 -0.32 ) ( -1.5660 )
A = ( -0.11 2.93 0.81 ), B = ( -2.8425 )
( -0.32 0.81 -2.37 ) ( -1.1765 )
Sub Ex_Dspsvx()
Const N = 3
Dim Ap(N * (N + 1) / 2) As Double, Afp(N * (N + 1) / 2) As Double, IPiv(N - 1) As Long
Dim B(N - 1) As Double, X(N - 1) As Double
Dim FErr(0) As Double, BErr(0) As Double
Dim RCond As Double, Info As Long
Ap(0) = 2.2
Ap(1) = -0.11: Ap(3) = 2.93
Ap(2) = -0.32: Ap(4) = 0.81: Ap(5) = 2.37:
B(0) = -1.566: B(1) = -2.8425: B(2) = -1.1765
Call Dspsvx("N", "L", N, Ap(), Afp(), IPiv(), B(), X(), RCond, FErr(), BErr(), Info)
Debug.Print "X =", X(0), X(1), X(2)
Debug.Print "RCond =", RCond
Debug.Print "Info =", Info
End Sub
Sub Dspsvx(Fact As String, Uplo As String, N As Long, Ap() As Double, Afp() As Double, IPiv() As Long, B() As Double, X() As Double, RCond As Double, FErr() As Double, BErr() As Double, Info As Long, Optional Nrhs As Long=1)
(Expert driver) Solution to system of linear equations AX = B for a symmetric matrix
Example Results
X = -0.8 -0.92 -0.29
RCond = 0.446791078068956
Info = 0