UpperTriangularMatrixQ
Details and Options
- UpperTriangularMatrixQ[m,k] works even if m is not a square matrix.
- In UpperTriangularMatrixQ[m,k], positive k refers to superdiagonals above the main diagonal and negative k refers to subdiagonals below the main diagonal.
- UpperTriangularMatrixQ works with SparseArray and structured array objects.
- The following option can be given:
-
Tolerance Automatic numerical tolerance to use - For approximate matrices, the option Tolerance->t can be used to indicate that all entries Abs[mij]≤t are taken to be zero. »
Examples
open all close allBasic Examples (3)
Test if a matrix is upper triangular:
UpperTriangularMatrixQ[(| | | |
| - | - | - |
| a | b | c |
| 0 | e | f |
| 0 | 0 | g |)]UpperTriangularMatrixQ[(| | | |
| - | - | - |
| 1 | 2 | 3 |
| 4 | 5 | 6 |
| 7 | 8 | 9 |)]Test if a matrix is upper triangular starting from the first superdiagonal:
MatrixForm[{{0, 1, 2}, {0, 0, 3}, {0, 0, 0}}]UpperTriangularMatrixQ[%, 1]Test if a matrix is upper triangular starting from the first subdiagonal:
MatrixForm[{{1, 2, 3}, {4, 5, 6}, {0, 7, 9}}]UpperTriangularMatrixQ[%, -1]Scope (12)
Basic Uses (8)
(mat23 = {{1, 2, 3}, {0, 4, 5}})//MatrixFormUpperTriangularMatrixQ[mat23](mat32 = {{1, 2}, {0, 4}, {0, 0}})//MatrixFormUpperTriangularMatrixQ[mat32]UpperTriangularMatrixQ[{{a, b}, {c, d}}]The matrix is upper triangular when c=0:
UpperTriangularMatrixQ[{{a, b}, {c, d}} /. c -> 0]Test if a real machine-number matrix is upper triangular:
UpperTriangularMatrixQ[{{1.5, 0, 0}, {2.2, 3.1, 0}, {4.7, 5.2, 6.4}}]UpperTriangularMatrixQ[{{1. + I, 2, 3 - 2 I}, {0, 4, 5I}, {0, 0, 6}}]UpperTriangularMatrixQ[{{1, Sqrt[2]}, {Pi, 1 / 2}}]Test an arbitrary-precision matrix:
UpperTriangularMatrixQ[N[{{1, Sqrt[2]}, {0, 1 / 2}}, 20]]Test if matrices have nonzero entries starting from a particular superdiagonal:
UpperTriangularMatrixQ[(| | | | |
| - | - | - | -- |
| 0 | 2 | 3 | 4 |
| 0 | 0 | 7 | 8 |
| 0 | 0 | 0 | 12 |
| 0 | 0 | 0 | 0 |), 1]UpperTriangularMatrixQ[(| | | | |
| - | - | - | -- |
| 0 | 2 | 3 | 4 |
| 0 | 0 | 7 | 8 |
| 0 | 0 | 0 | 12 |
| 0 | 0 | 0 | 0 |), 2]Note that this matrix is upper triangular:
UpperTriangularMatrixQ[(| | | | |
| - | - | - | -- |
| 0 | 2 | 3 | 4 |
| 0 | 0 | 7 | 8 |
| 0 | 0 | 0 | 12 |
| 0 | 0 | 0 | 0 |)]Test if matrices have nonzero entries starting from a particular subdiagonal:
UpperTriangularMatrixQ[(| | | | |
| - | -- | -- | -- |
| 1 | 2 | 3 | 4 |
| 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 |
| 0 | 14 | 15 | 16 |), -1]UpperTriangularMatrixQ[(| | | | |
| - | -- | -- | -- |
| 1 | 2 | 3 | 4 |
| 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 |
| 0 | 14 | 15 | 16 |), -2]Note that this matrix is not upper triangular:
UpperTriangularMatrixQ[(| | | | |
| - | -- | -- | -- |
| 1 | 2 | 3 | 4 |
| 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 |
| 0 | 14 | 15 | 16 |)]Special Matrices (4)
mat = SparseArray[{{1, 1} -> 2, {1, 2} -> 1, {2, 3} -> 5}, {3, 3}]UpperTriangularMatrixQ[mat]SymmetrizedArray[{{1, 1} -> 2, {1, 2} -> 1}, {2, 2}, Symmetric[All]]UpperTriangularMatrixQ[%]QuantityArray[{{6, 5}, {0, 3}, {0, 0}}, {"Meters", "Seconds"}]UpperTriangularMatrixQ[%]Identity matrices are upper triangular:
UpperTriangularMatrixQ[IdentityMatrix[5]]Hilbert matrices are not upper triangular:
UpperTriangularMatrixQ[HilbertMatrix[3]]Options (1)
Tolerance (1)
This matrix is not upper triangular:
m = {{1., 2., 3.}, {10 ^ -12, 4., 5.}, {0, 10 ^ -13, 6.}};
UpperTriangularMatrixQ[m]Add the Tolerance option to consider numbers smaller than 10-12 to be zero:
UpperTriangularMatrixQ[m, Tolerance -> 10 ^ -12]Applications (2)
SchurDecomposition gives a 2×2-block upper-triangular matrix:
{q, t} = SchurDecomposition[RandomReal[1., {5, 5}]];MatrixForm[t]Verify this matrix is upper triangular starting from the first subdiagonal:
{UpperTriangularMatrixQ[t], UpperTriangularMatrixQ[t, -1]}JordanDecomposition relates any matrix to an upper-triangular matrix via a similarity transformation
:
m = {{1, 0, 0, 0}, {0, 1, 0, 0}, {1, -1, 1, 0}, {1, -1, 1, 1}};
{s, j} = JordanDecomposition[m];MatrixForm /@ {m, j, s}Verify that the Jordan matrix is upper triangular and similar to the original matrix:
{UpperTriangularMatrixQ[j], m == s.j.Inverse[s]}The matrix
is diagonalizable iff its Jordan matrix
is also lower triangular:
{LowerTriangularMatrixQ[j], DiagonalizableMatrixQ[m]}Properties & Relations (12)
UpperTriangularMatrixQ returns False for inputs that are not matrices:
UpperTriangularMatrixQ[1]UpperTriangularMatrixQ[{}]Matrices of dimensions {n,0} are upper triangular:
UpperTriangularMatrixQ[{{}, {}}]UpperTriangularize returns matrices that are UpperTriangularMatrixQ:
UpperTriangularMatrixQ[UpperTriangularize[{{a, b}, {c, d}}]]The inverse of an upper-triangular matrix is upper triangular:
mat = UpperTriangularize[RandomInteger[{1, 10}, {5, 5}]];UpperTriangularMatrixQ[Inverse[mat]]This extends to arbitrary powers and functions:
UpperTriangularMatrixQ[MatrixPower[mat, n]]UpperTriangularMatrixQ[MatrixFunction[f, mat]]The product of two (or more) upper-triangular matrices is upper triangular:
m1 = UpperTriangularize[RandomReal[1., {5, 5}]];
m2 = UpperTriangularize[RandomReal[1., {5, 5}]];UpperTriangularMatrixQ[m1.m2]The determinant of a triangular matrix equals the product of the diagonal entries:
m = UpperTriangularize[RandomReal[1., {5, 5}]];UpperTriangularMatrixQ[m]Det[m] == Apply[Times, Diagonal[m]]Eigenvalues of a triangular matrix equal its diagonal elements:
m = UpperTriangularize[RandomReal[1., {5, 5}]];UpperTriangularMatrixQ[m]Eigenvalues[m] == Reverse@Sort@Diagonal[m]UpperTriangularMatrixQ[m,0] is equivalent to UpperTriangularMatrixQ[m]:
{UpperTriangularMatrixQ[{{1, 0}, {0, 2}}], UpperTriangularMatrixQ[{{1, 0}, {0, 2}}, 0]}{UpperTriangularMatrixQ[{{1, 3}, {4, 2}}], UpperTriangularMatrixQ[{{1, 3}, {4, 2}}, 0]}QRDecomposition gives an upper triangular matrix:
{q, r} = QRDecomposition[RandomReal[1., {5, 5}]];UpperTriangularMatrixQ[r]CholeskyDecomposition gives an upper triangular matrix:
CholeskyDecomposition[{{2, 1}, {1, 2}}]UpperTriangularMatrixQ[%]HessenbergDecomposition returns a matrix that is upper triangular with an added subdiagonal:
{p, h} = HessenbergDecomposition[RandomReal[1., {5, 5}]];UpperTriangularMatrixQ[h, -1]A matrix is upper triangular starting at diagonal
iff its transpose is lower triangular starting at diagonal
:
k = RandomInteger[{-2, 2}];
m = UpperTriangularize[RandomReal[1., {5, 5}], k];UpperTriangularMatrixQ[m, k] == LowerTriangularMatrixQ[Transpose[m], -k]Tech Notes
Related Guides
History
Text
Wolfram Research (2019), UpperTriangularMatrixQ, Wolfram Language function, https://reference.wolfram.com/language/ref/UpperTriangularMatrixQ.html.
CMS
Wolfram Language. 2019. "UpperTriangularMatrixQ." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/UpperTriangularMatrixQ.html.
APA
Wolfram Language. (2019). UpperTriangularMatrixQ. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/UpperTriangularMatrixQ.html
BibTeX
@misc{reference.wolfram_2026_uppertriangularmatrixq, author="Wolfram Research", title="{UpperTriangularMatrixQ}", year="2019", howpublished="\url{https://reference.wolfram.com/language/ref/UpperTriangularMatrixQ.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_uppertriangularmatrixq, organization={Wolfram Research}, title={UpperTriangularMatrixQ}, year={2019}, url={https://reference.wolfram.com/language/ref/UpperTriangularMatrixQ.html}, note=[Accessed: 13-June-2026]}