diff --git a/README.md b/README.md index ce93985d..56001a9b 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,7 @@ Various Math algorithms: - [Fast Exponentiation](https://github.com/manrajgrover/algorithms-js/blob/master/src/algorithms/math/fast_exp.js) - [GCD](https://github.com/manrajgrover/algorithms-js/blob/master/src/algorithms/math/gcd.js) - [LCM](https://github.com/manrajgrover/algorithms-js/blob/master/src/algorithms/math/lcm.js) +- [Tridiagonal Algorithm](https://github.com/manrajgrover/algorithms-js/blob/master/src/algorithms/math/tridiagonal_algorithm.js) #### String Various String algorithms: diff --git a/docs/README.md b/docs/README.md index 0f4eb555..1b4a0f6d 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,4 +1,4 @@ -# [algorithms-js](https://github.com/manrajgrover/algorithms-js#readme) *0.0.8* +# [algorithms-js](https://github.com/manrajgrover/algorithms-js#readme) *0.0.13* > Algorithms Library in JavaScript @@ -254,6 +254,35 @@ Calculates LCM of two numbers +### src/algorithms/math/matrix_determinant.js + + +#### matrixDeterminant(M) + +Calculates the determinant of a non-singular matrix +with real entries using Bareiss's algorithm. + + + + +##### Parameters + +| Name | Type | Description | | +| ---- | ---- | ----------- | -------- | +| M | `Array` | Matrix with real entries. | | + + + + +##### Returns + + +- `Number` determinant of the matrix M. +Reference: https://en.wikipedia.org/wiki/Bareiss_algorithm + + + + ### src/algorithms/math/modular_inverse.js @@ -306,6 +335,69 @@ Calculates modular inverse of a number +### src/algorithms/math/tridiagonal_algorithm.js + + +#### extractTridiagonalCoefficients(A, pad) + +Extracts the tridiagonal coefficients from +a square matrix A. Pads the upper and lower +diagonal arrays to ensure all three diagonals +are of equal length. + + + + +##### Parameters + +| Name | Type | Description | | +| ---- | ---- | ----------- | -------- | +| A | `Array` | Square matrix. | | +| pad | `boolean` | If true, pads lower and upper diagonal arrays. | | + + + + +##### Returns + + +- `Object` Returns object with keys `lowerDiagonal`, `centralDiagonal` and `upperDiagonal`. + + + +#### tridiagonalAlgorithm(A, d) + +Solves a linear system Ax=b where A is a tridiagonal matrix. + +Note: the method is only stable in some special cases +such as when the matrix is diagonally dominant or symmetric +positive definite (See reference). +For an algorithm stable in the general case, see: +http://www2.stat.duke.edu/~sayan/863/lec/linsys.pdf + + + + +##### Parameters + +| Name | Type | Description | | +| ---- | ---- | ----------- | -------- | +| A | `Array` | Tridiagonal Maxtrix. | | +| d | `Array` | Vector of values. | | + + + + +##### Returns + + +- array representing the solution vector x. Returns null if system is singular. + +Reference: https://en.wikipedia.org/wiki/Tridiagonal_matrix_algorithm + + + + ### src/algorithms/search/binary_search.js diff --git a/docs/index.html b/docs/index.html index 9294cff2..44a483f2 100644 --- a/docs/index.html +++ b/docs/index.html @@ -3,7 +3,7 @@
-Algorithms Library in JavaScript
@@ -295,6 +295,21 @@Calculates the determinant of a non-singular matrix +with real entries using Bareiss's algorithm.
+ + +Name | +Type | +Description | ++ |
---|---|---|---|
M | +
+ Array
+ |
+ Matrix with real entries. + |
+ + | +
+ Number
+
determinant of the matrix M. +Reference: https://en.wikipedia.org/wiki/Bareiss_algorithm
+ + + +Extracts the tridiagonal coefficients from +a square matrix A. Pads the upper and lower +diagonal arrays to ensure all three diagonals +are of equal length.
+ + +Name | +Type | +Description | ++ |
---|---|---|---|
A | +
+ Array
+ |
+ Square matrix. + |
+ + | +
pad | +
+ boolean
+ |
+ If true, pads lower and upper diagonal arrays. + |
+ + | +
+ Object
+
Returns object with keys lowerDiagonal
, centralDiagonal
and upperDiagonal
.
Solves a linear system Ax=b where A is a tridiagonal matrix.
+Note: the method is only stable in some special cases +such as when the matrix is diagonally dominant or symmetric +positive definite (See reference). +For an algorithm stable in the general case, see: +http://www2.stat.duke.edu/~sayan/863/lec/linsys.pdf
+ + +Name | +Type | +Description | ++ |
---|---|---|---|
A | +
+ Array
+ |
+ Tridiagonal Maxtrix. + |
+ + | +
d | +
+ Array
+ |
+ Vector of values. + |
+ + | +
+
+ +array representing the solution vector x. Returns null if system is singular.
+Reference: https://en.wikipedia.org/wiki/Tridiagonal_matrix_algorithm
+ + + +