cgsolve {cPCG} | R Documentation |
Conjugate gradient method for solving system of linear equations Ax = b, where A is symmetric and positive definite, b is a column vector.
cgsolve(A, b, tol = 1e-6, maxIter = 1000)
A |
matrix, symmetric and positive definite. |
b |
vector, with same dimension as number of rows of A. |
tol |
numeric, threshold for convergence, default is |
maxIter |
numeric, maximum iteration, default is |
The idea of conjugate gradient method is to find a set of mutually conjugate directions for the unconstrained problem
arg min_x f(x)
where f(x) = 0.5 b^T A b - bx + z and z is a constant. The problem is equivalent to solving Ax = b.
This function implements an iterative procedure to reduce the number of matrix-vector multiplications [1]. The conjugate gradient method improves memory efficiency and computational complexity, especially when A is relatively sparse.
Returns a vector representing solution x.
Users need to check that input matrix A is symmetric and positive definite before applying the function.
[1] Yousef Saad. Iterative methods for sparse linear systems. Vol. 82. siam, 2003.
## Not run: test_A <- matrix(c(4,1,1,3), ncol = 2) test_b <- matrix(1:2, ncol = 1) cgsolve(test_A, test_b, 1e-6, 1000) ## End(Not run)