cg | R Documentation |
Conjugate gradients (CG) method is an iterative algorithm for solving linear systems with positive definite coefficient matrices.
cg(a, b, maxiter = 200, tol = 1e-7)
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 |
tol |
tolerance level for stopping iterations. |
a vector with the approximate solution, the iterations performed are returned as the attribute 'iterations'.
The underlying C
code does not check for symmetry nor positive definitiveness.
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.
jacobi
, seidel
, solve
a <- matrix(c(4,3,0,3,4,-1,0,-1,4), ncol = 3)
b <- c(24,30,-24)
z <- cg(a, b)
z # converged in 3 iterations
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.