# cgsolve: Conjugate gradient method In cPCG: Efficient and Customized Preconditioned Conjugate Gradient Method for Solving System of Linear Equations

## Description

Conjugate gradient method for solving system of linear equations Ax = b, where A is symmetric and positive definite, b is a column vector.

## Usage

 `1` ```cgsolve(A, b, tol = 1e-6, maxIter = 1000) ```

## Arguments

 `A` matrix, symmetric and positive definite. `b` vector, with same dimension as number of rows of A. `tol` numeric, threshold for convergence, default is `1e-6`. `maxIter` numeric, maximum iteration, default is `1000`.

## Details

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.

## Value

Returns a vector representing solution x.

## Warning

Users need to check that input matrix A is symmetric and positive definite before applying the function.

## References

[1] Yousef Saad. Iterative methods for sparse linear systems. Vol. 82. siam, 2003.

`pcgsolve`

## Examples

 ```1 2 3 4 5 6``` ```## 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) ```

### Example output

```           [,1]
[1,] 0.09090909
[2,] 0.63636364
```

cPCG documentation built on May 2, 2019, 11:04 a.m.