Home > @josh-brown/vector > MatrixBuilder > tridiagonal
Constructs a square tridiagonal matrix whose diagonal entries correspond to the entries of diagonalEntries
, whose entries in the left-off-diagonal correspond to the entries of leftEntries
, and whose entries in the right-off-diagonal correspond fo the entries of rightEntries
. The off-diagonals must have one fewer entry than the diagonal. Throws an error if the dimensions are not correct.
Signature:
tridiagonal(leftEntries: Vector<S>, diagonalEntries: Vector<S>, rightEntries: Vector<S>): M;
Parameter | Type | Description |
---|---|---|
leftEntries | Vector<S> | A vector whose entries will be used in the left off-diagonal |
diagonalEntries | Vector<S> | A vector whose entries will be used in the diagonal |
rightEntries | Vector<S> | A vector whose entries will be used in the right off-diagonal |
Returns:
M
The new matrix
const leftEntries = NumberVector.fromEntries(1, 2);
const diagonalEntries = NumberVector.fromEntries(3, 4, 5);
const rightEntries = NumberVector.fromEntries(6, 7);
const tridiagonal = matrixBuilder.tridiagonal(leftEntries, diagonalEntries, rightEntries);
// [ 3 6 0 ]
// [ 1 4 7 ]
// [ 0 2 5 ]