solve-banded
v1.0.4
Published
Solve a system of banded linear equations
Downloads
28
Maintainers
Readme
solve-banded
Solve a system of banded linear equations
Introduction
This module accepts javascript Arrays or typed arrays representing the bands of a banded matrix and computes the solution using the Thomas Algorithm. A system with one subdiagonal and two superdiagonal bands, for example, looks like:
The solver will fail if the matrix is singular and may not succeed if the matrix is not diagonally dominant. If the solver fails, it will log a console message and return false. Note that the solver accepts a stride and offset for the input/output vector (x
, below), so that a system can be solved in-place in an ndarray. The coefficient matrix does not currently accept strides or offsets and must be passed as individual vectors.
Example
Consider the solution of the tridiagonal system
var solveBanded = require('solve-banded')
var e = [4, 25, -5]
solveBanded([[0, -1, 2], [2, 7, -3], [1, 4, 0]], 1, 1, e, 3)
console.log(e)
// => e = [ 1, 2, 3 ]
Installation
$ npm install solve-banded
API
require('solve-banded')(diagonals, nsub, nsup, x, nx [, ox = 0 [, sx = 1]])
Arguments:
diagonals
: an array of diagonal bands, starting with with the subdiagonal-most band (a in the example matrix above) and proceeding to the superdiagonal-most band (d in the example matrix above). Each vector must be a javascriptArray
or typed array of lengthnx
.nsub
: an integer representing the number of subdiagonal bands, excluding the diagonal.nsup
: an integer representing the number of superdiagonal bands, excluding the diagonal.x
: a javascriptArray
or typed array of lengthnx
representing the known vector (e in the example matrix above). On successful completion, this vector will contain the solution.nx
: an integer representing the number of equations, i.e. the length ofx
.ox
(optional): an integer representing the offset of data inx
. If not provided, assumed equal to zero.sx
(optional): an integer representing the stride of data inx
. If not provided, assumed equal to one.
Returns: True on successful completion, false otherwise.
License
© 2016 Ricky Reusser. MIT License.