2.0.0 • Published 8 years ago

solve-tridiagonal v2.0.0

Weekly downloads
4
License
MIT
Repository
github
Last release
8 years ago

solve-tridiagonal Build Status npm version js-standard-style

Solve a system of linear tridiagonal equations

Introduction

This module accepts javascript Arrays or typed arrays representing the bands of a tridiagonal matrix and computes the solution using the Thomas algorithm. The problem in matrix form is

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.

Example

Consider the solution of

var tdiag = require('solve-tridiagonal')

var d = [4, 25, -5]

tdiag([0, -1, 2], [2, 7, -3], [1, 4, 0], d)
// => d = [ 1, 2, 3 ]

Installation

$ npm install solve-tridiagonal

API

require('solve-tridiagonal')(n, a, b, c, d)

Arguments:

  • n: an integer representing the number of equations to be solved
  • a: a javascript Array or typed array of length n representing the subdiagonal, indexed according to the equation above. Left unchanged by the solver.
  • b: a javascript Array or typed array of length n representing the diagonal, indexed as above. This vector is modified by the solver.
  • c: a javascript Array or typed array of length n representing the superdiagonal, indexed as above. This vector is modified by the solver.
  • d: a javascript Array or typed array of length n representing the known vector d. On successful completion, this vector will contain the solution.

Returns: True on successful completion, false otherwise.

License

© 2016 Ricky Reusser. MIT License.