|
|
◆ ZCg()
| Sub ZCg |
( |
N As |
Long, |
|
|
Val() As |
Complex, |
|
|
Ptr() As |
Long, |
|
|
Ind() As |
Long, |
|
|
B() As |
Complex, |
|
|
X() As |
Complex, |
|
|
Optional Info As |
Long, |
|
|
Optional Iter As |
Long, |
|
|
Optional Res As |
Double, |
|
|
Optional Format As |
Long = 0, |
|
|
Optional MaxIter As |
Long = 500, |
|
|
Optional Tol As |
Double = 1.0E-10, |
|
|
Optional Uplo As |
String = "F", |
|
|
Optional Base As |
Long = -1, |
|
|
Optional Precon As |
Long = 0, |
|
|
Optional Omega As |
Double = 1.5 |
|
) |
| |
Solution of linear system Ax = b using conjugate gradient (CG) method (Hermitian positive definite matrices) (driver)
- Purpose
- This routine solves the linear system Ax = b with Hermitian positive definite coefficient matrix using the conjugate gradient (CG) method with preconditioning. Matrix A is represented in CSR or CSC format.
- Parameters
-
| [in] | N | Dimension of the matrix A. (N >= 0) (if N = 0, returns without computation) |
| [in] | Val() | Array Val(LVal - 1) (LVal >= Nnz) (Nnz is the number of nonzero elements of the matrix A)
Values of nonzero elements of the matrix A. |
| [in] | Ptr() | Array Ptr(LPtr - 1) (LPtr >= N + 1)
Column pointers (if CSC) or row pointers (if CSR) of the matrix A. |
| [in] | Ind() | Array Ind(LInd - 1) (LInd >= Nnz)
Row indices (if CSC) or column indices (if CSR) of the matrix A. |
| [in] | B() | Array B(LB - 1) (LB >= N)
Right hand side vector b. |
| [in,out] | X() | Array X(LX - 1) (LX >= N)
[in] Initial guess of solution.
[out] Obtained approximate solution. |
| [out] | Info | (Optional)
= 0: Successful exit
= i < 0: The (-i)-th argument is invalid.
= 1: (Warning) Matrix A is not positive definite (computation continued).
= 2: (Warning) Preconditioner matrix M is not positive definite (computation continued).
= 11: Maximum number of iterations exceeded.
= 12: Matrix A is singular (zero diagonal element).
= 13: Error during initializing preconditioner.
= 14: Error during preconditioning. |
| [out] | Iter | (Optional)
Actual number of iterations performed for convergence. |
| [out] | Res | (Optional)
Final residual norm value norm(b - A*x). |
| [in] | Format | (Optional)
Sparse matrix format. (default = 0)
= 0: CSR format.
= 1: CSC format. |
| [in] | MaxIter | (Optional)
Maximum number of iterations. (MaxIter > 0) (default = 500) |
| [in] | Tol | (Optional)
Tolerance for convergence test. (default = 1.0e-10)
Assumed to be converged if norm(b - A*x) <= Tol*norm(b).
If Tol < eps (machine epsilon), Tol = eps is assumed. |
| [in] | Uplo | (Optional)
Specifies whether the upper or lower triangular part of matrix A is stored. (default = "F")
= "U": Upper triangular part is stored.
= "L": Lower triangular part is stored.
= "F": Full matrix (both upper and lower triangular parts) are stored. |
| [in] | Base | (Optional)
Indexing of Ptr() and Ind().
= 0: Zero-based (C style) indexing: Starting index is 0.
= 1: One-based (Fortran style) indexing: Starting index is 1.
(default: Assumes 1 if Ptr(0) = 1, 0 otherwise) |
| [in] | Precon | (Optional)
Specify preconditioner. (default = 0)
= 0: No preconditioner.
= 1: Diagonal scaling preconditioner.
= 2: SSOR preconditioner.
= 3: IC0 preconditioner. |
| [in] | Omega | (Optional)
The relaxation parameter ω of SSOR preconditioner. (0 < ω < 2) (default = 1.5)
Not used if Precon <> 2. |
- Example Program
- Solve the system of linear equations Ax = B, where
( 1.4 -1.5+0.46i 0.16+0.23i )
A = ( -1.5-0.46i 1.44 -0.12+0.04i )
( 0.16-0.23i -0.12-0.04i 0.05 )
( -2.3215-1.1316i )
B = ( 1.7972+2.0692i )
( -0.4042-0.0049i )
Sub Ex_ZCg()
Const N = 3, Nnz = 6
Dim A(Nnz - 1) As Complex, Ia(N) As Long, Ja(Nnz - 1) As Long
Dim B(N - 1) As Complex, X(N - 1) As Complex
Dim Iter As Long, Res As Double, Info As Long
Ia(0) = 0: Ia(1) = 1: Ia(2) = 3: Ia(3) = 6
Ja(0) = 0: Ja(1) = 0: Ja(2) = 1: Ja(3) = 0: Ja(4) = 1: Ja(5) = 2
B(0) = Cmplx(-2.3215, -1.1316): B(1) = Cmplx(1.7972, 2.0692): B(2) = Cmplx(-0.4042, -0.0049)
Call ZCg(N, A(), Ia(), Ja(), B(), X(), Info, Iter, Res, Uplo:="L")
Debug.Print "X ="
Debug.Print "(" + CStr( Creal(X(0))) + "," + CStr( Cimag(X(0))) + ")"
Debug.Print "(" + CStr( Creal(X(1))) + "," + CStr( Cimag(X(1))) + ")"
Debug.Print "(" + CStr( Creal(X(2))) + "," + CStr( Cimag(X(2))) + ")"
Debug.Print "Iter =" + Str(Iter) + ", Res =" + Str(Res) + ", Info =" + Str(Info)
End Sub
Function Cmplx(R As Double, Optional I As Double=0) As Complex Building complex number
Function Cimag(A As Complex) As Double Imaginary part of complex number
Function Creal(A As Complex) As Double Real part of complex number
Sub ZCg(N As Long, Val() As Complex, Ptr() As Long, Ind() As Long, B() As Complex, X() As Complex, Optional Info As Long, Optional Iter As Long, Optional Res As Double, Optional Format As Long=0, Optional MaxIter As Long=500, Optional Tol As Double=1.0E-10, Optional Uplo As String="F", Optional Base As Long=-1, Optional Precon As Long=0, Optional Omega As Double=1.5) Solution of linear system Ax = b using conjugate gradient (CG) method (Hermitian positive definite ma...
- Example Results
X =
(-0.819999999999983,-0.939999999999992)
(0.739999999999985,0.199999999999988)
(0.480000000000001,0.209999999999999)
Iter = 3, Res = 8.08057086495744E-14, Info = 0
|