({{, (RefLink[UpperTriangularMatrixQ, paclet:ref/UpperTriangularMatrixQ])[m] 
gives (RefLink[True, paclet:ref/True]) if m is upper triangular, and (RefLink[False, paclet:ref/False]) otherwise.}, {, (RefLink[UpperTriangularMatrixQ, paclet:ref/UpperTriangularMatrixQ])[m,k]
gives (RefLink[True, paclet:ref/True]) if m is upper triangular starting up from the k(^th) diagonal, and (RefLink[False, paclet:ref/False]) otherwise.}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[UpperTriangularMatrixQ, paclet:ref/UpperTriangularMatrixQ])[m,k] works even if m is not a square matrix.

In (RefLink[UpperTriangularMatrixQ, paclet:ref/UpperTriangularMatrixQ])[m,k], positive k refers to superdiagonals above the main diagonal and negative k refers to subdiagonals below the main diagonal.

(RefLink[UpperTriangularMatrixQ, paclet:ref/UpperTriangularMatrixQ]) works with (RefLink[SparseArray, paclet:ref/SparseArray]) and (RefLink[StructuredArray, paclet:ref/StructuredArray]) objects.

For approximate matrices, the option (RefLink[Tolerance, paclet:ref/Tolerance])->t can be used to indicate that all entries (RefLink[Abs, paclet:ref/Abs])[(Subscript[m, ij])]≤t are taken to be zero.

OpenersPrimaryExamplesSection(Spacer1)Examples  (26)

OpenersExampleSection0(Spacer1)Basic Examples  (3)

Test if a matrix is upper triangular:

MatrixForm[{{a,b,c},{0,e,f},{0,0,g}}]

UpperTriangularMatrixQ[%]

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]

OpenersExampleSection1(Spacer1)Scope  (7)

Test if a real machine-number matrix is upper triangular:

UpperTriangularMatrixQ[N[{{1,2,3},{0,4,5},{0,0,6}}]]

A complex matrix:

UpperTriangularMatrixQ[{{1.+I,2,3-2 I},{0,4,5I},{0,0,6}}]

An exact matrix:

UpperTriangularMatrixQ[{{1,(Sqrt[2])},{Pi,1/2}}]

An arbitrary-precision matrix:

UpperTriangularMatrixQ[N[{{1,(Sqrt[2])},{0,1/2}},20]]

Test a sparse matrix:

mat=SparseArray[{{1,1}->2,{1,2}->1,{2,3}->5},{3,3}]

UpperTriangularMatrixQ[mat]

Test whether a structured matrix is upper triangular:

mat=SymmetrizedArray[{{1,1}->2,{1,2}->1},{2,2},Symmetric[All]]

UpperTriangularMatrixQ[mat]

Test a symbolic matrix:

UpperTriangularMatrixQ[{{a,b},{c,d}}]

The matrix is upper triangular when c=0:

UpperTriangularMatrixQ[{{a,b},{c,d}}/.c->0]

Test rectangular upper-triangular matrices:

(mat23={{1,2,3},{0,4,5}})//MatrixForm

UpperTriangularMatrixQ[mat23]

(mat32={{1,2},{0,4},{0,0}})//MatrixForm

UpperTriangularMatrixQ[mat32]

Test if matrices have nonzero entries starting from a particular superdiagonal:

UpperTriangularMatrixQ[{{0,1,2},{0,0,3},{0,0,0}},1]

UpperTriangularMatrixQ[{{0,1,2},{0,0,3},{0,0,0}},2]

The following matrix is upper triangular but not with respect to the first superdiagonal:

MatrixForm[{{1,0,4},{0,2,5},{0,0,3}}]

UpperTriangularMatrixQ[%,1]

Test if matrices have nonzero entries starting from a particular subdiagonal:

UpperTriangularMatrixQ[{{a,b,c},{d,e,f},{g,h,i}},-1]

UpperTriangularMatrixQ[{{a,b,c},{d,e,f},{g,h,i}},-2]

OpenersExampleSection2(Spacer1)Options  (1)

OpenersExampleSubsection0(Spacer1)Tolerance  (1)

This matrix is not upper triangular:

m={{1.,2.,3.},{10^-12,4.,5.},{0,10^-13,6.}};
UpperTriangularMatrixQ[m]

Add the (RefLink[Tolerance, paclet:ref/Tolerance]) option to consider numbers smaller than (10^(-12)) to be zero:

UpperTriangularMatrixQ[m,Tolerance->10^-12]

OpenersExampleSection3(Spacer1)Applications  (3)

(RefLink[LUDecomposition, paclet:ref/LUDecomposition]) decomposes a matrix as a product of upper- and lower-triangular matrices, returned as a triple {lu,perm,cond}:

{lu,perm,cond}=LUDecomposition[{{10,1,4},{2,1,6},{1,8,6}}];

Form the canonical matrices l and u from the composite matrix lu:

l=LowerTriangularize[lu,-1] + IdentityMatrix[3];
u=UpperTriangularize[lu];

Display the three matrices:

MatrixForm/@{lu,l,u}

Verify that l and u are lower and upper triangular, respectively:

{LowerTriangularMatrixQ[l],UpperTriangularMatrixQ[u]}

Reconstruct the original matrix as a permutation of the product of l and u:

Permute[l.u,perm]

(RefLink[SchurDecomposition, paclet:ref/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]}

(RefLink[JordanDecomposition, paclet:ref/JordanDecomposition]) relates any matrix to an upper-triangular matrix via a similarity transformation m==s.j.(Inverse[s]):

m={{1,0,0,0},{0,1,0,0},{1,-1,1,0},{1,-1,1,1}};
{s,j}=JordanDecomposition[m];

Visualize the three matrices:

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 m is diagonalizable iff its Jordan matrix j is also lower triangular:

{LowerTriangularMatrixQ[j],DiagonalizableMatrixQ[m]}

OpenersExampleSection4(Spacer1)Properties & Relations  (12)

(RefLink[UpperTriangularMatrixQ, paclet:ref/UpperTriangularMatrixQ]) returns (RefLink[False, paclet:ref/False]) for inputs that are not matrices:

UpperTriangularMatrixQ[1]

UpperTriangularMatrixQ[{}]

Matrices of dimensions {n,0} are upper triangular:

UpperTriangularMatrixQ[{{},{}}]

(RefLink[UpperTriangularize, paclet:ref/UpperTriangularize]) returns matrices that are (RefLink[UpperTriangularMatrixQ, paclet:ref/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]

(RefLink[QRDecomposition, paclet:ref/QRDecomposition]) gives an upper-triangular matrix:

{q,r}=QRDecomposition[RandomReal[1.,{5,5}]];

UpperTriangularMatrixQ[r]

(RefLink[CholeskyDecomposition, paclet:ref/CholeskyDecomposition]) gives an upper-triangular matrix:

CholeskyDecomposition[{{2,1},{1,2}}]

UpperTriangularMatrixQ[%]

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]

(RefLink[UpperTriangularMatrixQ, paclet:ref/UpperTriangularMatrixQ])[m,0] is equivalent to (RefLink[UpperTriangularMatrixQ, paclet:ref/UpperTriangularMatrixQ])[m]:

{UpperTriangularMatrixQ[{{1,0},{0,2}}],UpperTriangularMatrixQ[{{1,0},{0,2}},0]}

{UpperTriangularMatrixQ[{{1,3},{4,2}}],UpperTriangularMatrixQ[{{1,3},{4,2}},0]}

A matrix is upper triangular starting at diagonal k iff its transpose is lower triangular starting at diagonal -k:

k=RandomInteger[{-2,2}];
m=UpperTriangularize[RandomReal[1.,{5,5}],k];

UpperTriangularMatrixQ[m,k]==LowerTriangularMatrixQ[Transpose[m],-k]

(RefLink[HessenbergDecomposition, paclet:ref/HessenbergDecomposition]) returns a matrix that is upper triangular with an added first subdiagonal:

{p,h}=HessenbergDecomposition[RandomReal[1.,{5,5}]];

UpperTriangularMatrixQ[h,-1]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[UpperTriangularize, paclet:ref/UpperTriangularize])  ▪  (RefLink[LowerTriangularMatrixQ, paclet:ref/LowerTriangularMatrixQ])  ▪  (RefLink[DiagonalMatrixQ, paclet:ref/DiagonalMatrixQ])  ▪  (RefLink[Band, paclet:ref/Band])  ▪  (RefLink[LUDecomposition, paclet:ref/LUDecomposition])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Vectors and Matrices, paclet:tutorial/VectorsAndMatrices])}, {▪(RefLinkPlain[Constructing Matrices, paclet:tutorial/ConstructingMatrices])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Matrices and Linear Algebra, paclet:guide/MatricesAndLinearAlgebra])}, {▪(RefLinkPlain[Matrix Predicates, paclet:guide/MatrixPredicates])}})}})