Conjugate gradient solver
npm install conjugate-gradientThis code implements the conjugate gradient method using a Jacobi preconditioner.
npm install conjugate-gradient
``javascript
var pcg = require("conjugate-gradient")
, CSRMatrix = require("csr-matrix")
//Create a matrix
var A = CSRMatrix.fromDense([[-2, 1, 0],
[ 1,-2, 1],
[ 0, 1,-2]])
//Create input vector
var B = new Float64Array([1, 0, 0])
//Solve equation:
//
// A x = B
//
console.log(pcg(A, b))
`
* A is a symmetric positive definite matrix represented as a CSRMatrixb
* is an array of length nx0
* is an optional initial guess for the solution to the equation. If specified, the result of the solution will also get stored in this arraytolerance
* is a cutoff tolerance for the solution. (Default is 1e-5)max_iter` is the maximum number of iterations to run the solver. (Default is min(n, 20))
*
Returns An array encoding the solution to the equation Ax = b