Sidechair

matrix.is_triangular()

Browse the reference

Returns true when all items above the main diagonal are zero, or all items below it are zero.

Try it in the editor

An upper triangular matrix has zeros below the main diagonal and a lower triangular one has zeros above it; either counts. [[1, 2], [0, 3]] passes, [[1, 2], [4, 3]] fails because both sides hold a non-zero item.

Diagonal matrices qualify as both kinds. The determinant of a triangular matrix is the product of its diagonal, which is why they are cheap to work with.

Syntax

Pine Script
matrix.is_triangular(id: matrix<int/float>) -> series bool
matrix.is_triangular() -> series bool

Arguments

NameTypeDefaultDescription
idmatrix<int/float>requiredThe matrix checked for zeros on one side of the main diagonal, either above it or below it.

Returns

  • series bool: true when one whole side of the main diagonal is zero, otherwise false.
  • series bool: true when the receiving matrix is triangular, otherwise false.

Example

Pine ScriptUpper triangularOpen in editor
//@version=6
indicator("matrix.is_triangular: upper", overlay = false)
matrix<float> m = matrix.new<float>(2, 2, 1.0)
matrix.set(m, 1, 0, 0.0)
plot(matrix.is_triangular(m) ? 1 : 0, "Triangular")

See also

Runs on Sidechair