cholesky-solve[WIP]
This module solves sparse symmetric positive definite linear systems,
by finding the Cholesky decomposition(the LDL^T
decomposition, and not
the LL^T
decomposition), and then doing forward substitution and
backward substitution. It is basically a Javascript port of the paper
"Algorithm 8xx: a concise sparse Cholesky factorization package". This
kind of solver has many applications in digital geometry processing.
Install
npm install cholesky-solve
Example
var choleskySolve = // matrix dimension.const n = 10 /*Below we specify the sparse matrix: 1.7 0 0 0 0 0 0 0 0.13 00 1.0 0 0 0.02 0 0 0 0 0.010 0 1.5 0 0 0 0 0 0 00 0 0 1.1 0 0 0 0 0 00 0.02 0 0 2.6 0 0.16 0.09 0.52 0.530 0 0 0 0 1.2 0 0 0 00 0 0 0 0.16 0 1.3 0 0 0.560 0 0 0 0.09 0 0 1.6 0.11 00.13 0 0 0 0.52 0 0 0.11 1.4 00 0.01 0 0 0.53 0 0.56 0 0 3.1 Note that we only specify the coefficients on the diagonal, or above the diagonal. Since the matrix is symmetric,specifying the coefficients below the diagonal is completely redundant. Finally, the order in which the coefficients is specified in is not important. */ // the sparse matrix on left-hand side.var M = 2 2 15 1 1 10 1 4 002 5 5 12 7 7 16 4 4 26 3 3 11 4 7 009 4 6 016 0 0 17 4 8 052 0 8 013 6 6 13 7 8 011 4 9 053 8 8 14 9 9 31 1 9 001 6 9 056 // right-hand sidevar b = 0287 022 045 044 2486 072 155 1424 1621 3759 var P = M n // finally, solve the equation// Mx = b// and print x // the `prepare` method returns a function that can be used to solve// the equation for any value of b.var solve = choleskySolveconsole
API
require("cholesky-solve").prepare(M, n, [P])
Decomposes M
into the Cholesky decomposition of the form LDL^T
. A
function is returned that can be used to solve the equation Mx = b
,
for some given value of b
.
M
a list of the matrix coefficients of the sparse matrixM
. These are the coefficients on the diagonal and above the diagonal. The ones below the diagonal do not need to be specified, since the matrix is symmetric.n
the dimension of the matrixM
P
encodes a permutation matrix that preconditionsM
before the Cholesky decomposition is solved for. A possible algorithm for finding a good permutation is Cuthill–McKee. See the module cuthill-mckee for a Javascript implementation.
Returns A function that takes a single argument b
. The function
returns the solution to the equation Mx = b
, encoded as a simple array.
NOTE the module does no sanity checking on the input arguments. It is assumed that the user knows what he/she is doing!