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

◆ ZCocg_r()

Sub ZCocg_r ( N As  Long,
B() As  Complex,
X() As  Complex,
Info As  Long,
XX() As  Complex,
YY() As  Complex,
IRev As  Long,
Optional Iter As  Long,
Optional Res As  Double,
Optional MaxIter As  Long = 500 
)

Solution of linear system Ax = b using conjugate orthogonal conjugate gradient (COCG) method (Complex symmetric matrices) (Reverse communication version)

Purpose
This routine solves the linear system Ax = b with complex symmetric coefficient matrix using the conjugate orthogonal conjugate gradient (COCG) method with preconditioning.

Cg_r is the reverse communication version of Cg so that the storage format of matrix A and the use of preconditioner can be flexibly selected.

Parameters
[in]NDimension of the matrix A. (N >= 0) (if N = 0, returns without computation)
[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= 0: Successful exit
< 0: The (-Info)-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).
[in,out]XX()Array XX(LXX - 1) (LXX >= N)
Vector XX for Matvec and Psolve operations.
[in,out]YY()Array YY(LYY - 1) (LYY >= N)
Vector YY for Matvec and Psolve operations.
[in,out]IRevControl variable for reverse communication.
[in] Before first call, IRev should be initialized to zero. On succeeding calls, IRev should not be altered (except if converged).
[out] If IRev is not zero, complete the following process and call this routine again.
= 0: Computation finished. See return code in info.
= 1: Matvec operation. User should set A*XX in YY. Do not alter any other variables.
= 3: Psolve operation. User should set solution of M*XX = YY in XX. Do not alter any other variables.
= 10: To be returned for the convergence test on every iteration . Set IRev = 11 if converged. Do not alter IRev otherwise. The latest values in X(), Iter and Res can be used to decide the convergence. Further, these values may be used to output the intermediate results.
[out]Iter(Optional)
Actual number of iterations performed for convergence.
[out]Res(Optional)
Final residual norm value norm(b - A*x).
[in]MaxIter(Optional)
Maximum number of iterations. (MaxIter > 0) (default = 500)
Example Program
Solve the system of linear equations Ax = B, where
( 0.31+0.77i 0.25+0.23i -0.81-0.83i )
A = ( 0.25+0.23i 0.26-0.26i -0.58-0.08i )
( -0.81-0.83i -0.56-0.08i 2.09+0.6i )
( 0.3941-1.2711i )
B = ( 0.0036-0.72i )
( 0.3628+1.9977i )
Sub Ex_ZCocg_r()
Const N = 3, Nnz = 6, Tol = 0.0000000001 '1.0e-10
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 XX(N - 1) As Complex, YY(N - 1) As Complex
Dim Iter As Long, Res As Double, IRev As Long, Info As Long, I As Long
A(0) = Cmplx(0.31, 0.77): A(1) = Cmplx(0.25, 0.23): A(2) = Cmplx(0.26, -0.26): A(3) = Cmplx(-0.81, -0.83): A(4) = Cmplx(-0.56, -0.08): A(5) = Cmplx(2.09, 0.6)
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(0.3941, -1.2711): B(1) = Cmplx(0.0036, -0.72): B(2) = Cmplx(0.3628, 1.9977)
IRev = 0
Do
Call ZCocg_r(N, B(), X(), Info, XX(), YY(), IRev, Iter, Res)
If IRev = 1 Then '- Matvec
Call SsrZusmv("L", N, Cmplx(1), A(), Ia(), Ja(), XX(), Cmplx(0), YY())
ElseIf IRev = 3 Then '- Psolve
For I = 0 To N - 1
XX(I) = YY(I)
Next
ElseIf IRev = 10 Then '- Check convergence
If Res < Tol Then IRev = 11
End If
Loop While IRev <> 0
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 SsrZusmv(Uplo As String, N As Long, Alpha As Complex, Val() As Complex, Rowptr() As Long, Colind() As Long, X() As Complex, Beta As Complex, Y() As Complex, Optional Info As Long, Optional Base As Long=-1, Optional IncX As Long=1, Optional IncY As Long=1)
y <- αAx + βy (CSR) (Complex symmetric matrix)
Sub ZCocg_r(N As Long, B() As Complex, X() As Complex, Info As Long, XX() As Complex, YY() As Complex, IRev As Long, Optional Iter As Long, Optional Res As Double, Optional MaxIter As Long=500)
Solution of linear system Ax = b using conjugate orthogonal conjugate gradient (COCG) method (Complex...
Example Results
X =
(-0.820000000000002,-0.940000000000001)
(0.739999999999999,0.199999999999999)
(0.480000000000005,0.209999999999999)
Iter = 3, Res = 1.44872095635518E-14, Info = 0