|
|
◆ cg1()
| def cg1 |
( |
uplo |
, |
|
|
n |
, |
|
|
val |
, |
|
|
rowptr |
, |
|
|
colind |
, |
|
|
b |
, |
|
|
x |
, |
|
|
tol |
= 1.0e-10, |
|
|
maxiter |
= 500 |
|
) |
| |
Solution of linear system Ax = b using conjugate gradient (CG) method (Symmetric positive definite) (Simple driver)
- Purpose
- This routine solves the linear system Ax = b with symmetric positive definite coefficient matrix using the conjugate gradient (CG) method. Matrix A is represented in CSR format.
- Returns
- (info, iter, res)
info (int):
= 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.
iter (int):
Final number of iterations.
res (float):
Final residual norm norm(b - A*x).
- Parameters
-
| [in] | uplo | Specifies whether the upper or lower triangular part of matrix A is stored.
= 'U': Upper triangular part is stored.
= 'L': Lower triangular part is stored.
= 'F': Full matrix (both upper and lower triangular parts) are stored. |
| [in] | n | Dimension of the matrix. (n >= 0) (If n = 0, returns without computation) |
| [in] | val | Numpy ndarray (1-dimensional, float, nnz)
Values of nonzero elements of matrix A (where nnz is the number of nonzero elements). |
| [in] | rowptr | Numpy ndarray (1-dimensional, int32, n + 1)
Row pointers of matrix A. |
| [in] | colind | Numpy ndarray (1-dimensional, int32, nnz)
Column indices of matrix A (where nnz is the number of nonzero elements). |
| [in] | b | Numpy ndarray (1-dimensional, float, n)
Right hand side vector b. |
| [in,out] | x | Numpy ndarray (1-dimensional, float, n)
[in] Initial guess of solution.
[out] Obtained approximate solution. |
| [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] | maxiter | (Optional)
Maximum number of iterations. (maxiter > 0) (default = 500) |
|