|
|
◆ ZSor()
| Sub ZSor |
( |
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 Omega As |
Double = 1.5, |
|
|
Optional MaxIter As |
Long = 500, |
|
|
Optional Tol As |
Double = 1.0E-10, |
|
|
Optional Base As |
Long = -1 |
|
) |
| |
Solution of linear system Ax = b using Successive over-relaxation (SOR) method (Complex matrices) (driver)
- Purpose
- This routine solves the linear system Ax = b using successive over-relaxation (SOR) iterative method. 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.
= 11: Maximum number of iterations exceeded.
= 12: Matrix is singular (zero diagonal element).
= 15: Internal error. |
| [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] | Omega | (Optional)
The relaxation parameter ω. (0 < ω < 2) (default = 1.5) |
| [in] | MaxIter | (Optional)
Maximum number of iterations. (MaxIter > 0) (default = 500)
If MaxIter <= 0, the default value is assumed. |
| [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] | 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) |
- Example Program
- Solve the system of linear equations Ax = B, where
( 4 0 1 0.7 0 )
( 2i 4 0 1 0.7 )
A = ( 0 2i 4 0 1 )
( 0 0 2i 4 0 )
( 0 0 0 2i 4 )
( 5.7 )
( 5.7 + 2i )
B = ( 5 + 2i )
( 4 + 2i )
( 4 + 2i )
Sub Ex_ZSor()
Const N = 5, Nnz = 14, Omega = 1.05
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) = 3: Ia(2) = 7: Ia(3) = 10: Ia(4) = 12: Ia(5) = 14
Ja(0) = 0: Ja(1) = 2: Ja(2) = 3: Ja(3) = 0: Ja(4) = 1: Ja(5) = 3: Ja(6) = 4: Ja(7) = 1: Ja(8) = 2: Ja(9) = 4: Ja(10) = 2: Ja(11) = 3: Ja(12) = 3: Ja(13) = 4
Call ZSor(N, A(), Ia(), Ja(), B(), X(), Info, Iter, Res, , Omega)
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 "(" + CStr( Creal(X(3))) + "," + CStr( Cimag(X(3))) + ")"
Debug.Print "(" + CStr( Creal(X(4))) + "," + CStr( Cimag(X(4))) + ")"
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 ZSor(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 Omega As Double=1.5, Optional MaxIter As Long=500, Optional Tol As Double=1.0E-10, Optional Base As Long=-1) Solution of linear system Ax = b using Successive over-relaxation (SOR) method (Complex matrices) (dr...
- Example Results
X =
( .999999999924489,-7.08452827945102E-11)
( .999999999965658, 7.93322103076301E-11)
( 1.00000000005495, 8.34202476797265E-12)
( .999999999994847,-2.33985620845386E-11)
( .999999999991225, 5.71383743476044E-12)
Iter = 11, Res = 4.1830004025201E-10, Info = 0
|