Skip to content

FEAT: Adds the tridiagonal algorithm. #135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
94 changes: 93 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand Down
Loading