cg: Solve linear systems using the conjugate gradients method

Description Usage Arguments Value Warning References See Also Examples

View source: R/cg.R

Description

Conjugate gradients (CG) method is an iterative algorithm for solving linear systems with positive definite coefficient matrices.

Usage

1
cg(a, b, maxiter = 200, tol = 1e-7)

Arguments

a

a symmetric positive definite matrix containing the coefficients of the linear system.

b

a vector of right-hand sides of the linear system.

maxiter

the maximum number of iterations. Defaults to 200

tol

tolerance level for stopping iterations.

Value

a vector with the approximate solution, the iterations performed are returned as the attribute 'iterations'.

Warning

The underlying C code does not check for symmetry nor positive definitiveness.

References

Golub, G.H., Van Loan, C.F. (1996). Matrix Computations, 3rd Edition. John Hopkins University Press.

Hestenes, M.R., Stiefel, E. (1952). Methods of conjugate gradients for solving linear equations. Journal of Research of the National Bureau of Standards 49, 409-436.

See Also

jacobi, seidel, solve

Examples

1
2
3
4
a <- matrix(c(4,3,0,3,4,-1,0,-1,4), ncol = 3)
b <- c(24,30,-24)
z <- cg(a, b)
z # 3 iterations

fastmatrix documentation built on Oct. 18, 2021, 5:08 p.m.

Related to cg in fastmatrix...