({{, (RefLink[UpperTriangularize, paclet:ref/UpperTriangularize])[m] 
gives a matrix in which all but the upper triangular elements of m are replaced with zeros. }, {, (RefLink[UpperTriangularize, paclet:ref/UpperTriangularize])[m,k]
replaces with zeros only the elements below the k(^th) subdiagonal of m.}})

OpenersNotesSection(Spacer1)Details

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

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

(RefLink[UpperTriangularize, paclet:ref/UpperTriangularize]) works with (RefLink[SparseArray, paclet:ref/SparseArray]) objects.

OpenersPrimaryExamplesSection(Spacer1)Examples  (6)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Get the upper triangular part of a matrix:

MatrixForm[UpperTriangularize[{{1,2,3},{4,5,6},{7,8,9}}]]

Get the strictly upper triangular part of a matrix:

MatrixForm[UpperTriangularize[{{1,2,3},{4,5,6},{7,8,9}},1]]

OpenersExampleSection1(Spacer1)Scope  (2)

Get the upper triangular part of nonsquare matrices:

MatrixForm[UpperTriangularize[{{1,2,3,4},{5,6,7,8},{9,10,11,12}}]]

MatrixForm[UpperTriangularize[{{1,2,3},{4,5,6},{7,8,9},{10,11,12}}]]

The number of rows or columns limits the meaningful values of the parameter k:

Table[MatrixForm[UpperTriangularize[{{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}}, k]],{k,-3,4}]

OpenersExampleSection3(Spacer1)Properties & Relations  (2)

Matrices returned by (RefLink[UpperTriangularize, paclet:ref/UpperTriangularize]) satisfy (RefLink[UpperTriangularMatrixQ, paclet:ref/UpperTriangularMatrixQ]):

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

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

(RefLink[UpperTriangularize, paclet:ref/UpperTriangularize])[m,k] is equivalent to (RefLink[Transpose, paclet:ref/Transpose])[(RefLink[LowerTriangularize, paclet:ref/LowerTriangularize])[(RefLink[Transpose, paclet:ref/Transpose])[m],-k]]:

m = RandomReal[1,{3,5}];
k = RandomInteger[{-2,4}];
{MatrixForm[u =UpperTriangularize[m,k]], u === Transpose[LowerTriangularize[Transpose[m], -k]]}

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[LowerTriangularize, paclet:ref/LowerTriangularize])  ▪  (RefLink[UpperTriangularMatrixQ, paclet:ref/UpperTriangularMatrixQ])  ▪  (RefLink[Diagonal, paclet:ref/Diagonal])  ▪  (RefLink[Band, paclet:ref/Band])  ▪  (RefLink[LUDecomposition, paclet:ref/LUDecomposition])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Matrices and Linear Algebra, paclet:guide/MatricesAndLinearAlgebra])}, {▪(RefLinkPlain[Linear Systems, paclet:guide/LinearSystems])}, {▪(RefLinkPlain[Parts of Matrices, paclet:guide/PartsOfMatrices])}})}})