Skip to content

Latest commit

 

History

History
65 lines (43 loc) · 1.25 KB

tri.md

File metadata and controls

65 lines (43 loc) · 1.25 KB

tri

Create a triangular matrix filled above or below the diagonal.

API

Numeric.create.tri(input, columns, diagonal = 0, method = 'mask')

Builds a matrix filled above or below the diagonal.

  • Parameters:
    • input: Number of rows or an existing matrix
    • columns: Number of columns in the matrix
    • diagonal: Diagonal offset of the triangle
    • method: Triangle side that is filled
  • Returns: Triangular matrix
  • NumPy: Covers np.tri, np.tril, np.triu through a single Numerix method.

Examples

Triangular matrix with ones below the diagonal

import Numeric from '@neabyte/numerix'

const matrix = Numeric.create.tri(3, 3)

console.log(matrix)
// [[1,0,0],[1,1,0],[1,1,1]]

Lower triangular matrix

import Numeric from '@neabyte/numerix'

const matrix = Numeric.create.tri(3, 3, 0, 'lower')

console.log(matrix)
// [[1,0,0],[1,1,0],[1,1,1]]

Upper triangular matrix

import Numeric from '@neabyte/numerix'

const matrix = Numeric.create.tri(3, 3, 0, 'upper')

console.log(matrix)
// [[1,1,1],[0,1,1],[0,0,1]]

Triangular matrix with a diagonal offset

import Numeric from '@neabyte/numerix'

const matrix = Numeric.create.tri(3, 3, 1)

console.log(matrix)
// [[1,1,0],[1,1,1],[1,1,1]]