| solve_cg | R Documentation | 
Solve the system l(x) = b where l(x) is a matrix-free
representation of the linear operation Ax.
solve_cg(l, b, init, args)
| l | A linear transformation of  | 
| b | A vector. | 
| init | Initial value of solution. | 
| args | List of additional arguments from  | 
A list with the form of a solve_cg_result described in section "Conjugate
Gradient" of the package vignette.
set.seed(1234)
n = 8
idx_diag = cbind(1:n, 1:n)
idx_ldiag = cbind(2:n, 1:(n-1))
idx_udiag = cbind(1:(n-1), 2:n)
b = rep(1, n)
## Solution by explicit computation of solve(A, b)
A = matrix(0, n, n)
A[idx_diag] = 2
A[idx_ldiag] = 1
A[idx_udiag] = 1
solve(A, b)
## Solve iteratively with solve_cg
f = function(x) { A %*% x }
args = cg_args()
init = rep(0, n)
solve_cg(f, b, init, args)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.