Returns true when all items above the main diagonal are zero, or all items below it are zero.
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
matrix.is_triangular(id: matrix<int/float>) -> series bool
matrix.is_triangular() -> series boolArguments
| Name | Type | Default | Description |
|---|---|---|---|
| id | matrix<int/ | required | The 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
//@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