gives a matrix in which all but the upper triangular elements of m are replaced with zeros.
UpperTriangularize[m,k]
replaces with zeros only the elements below the k
subdiagonal of m.
UpperTriangularize
gives a matrix in which all but the upper triangular elements of m are replaced with zeros.
UpperTriangularize[m,k]
replaces with zeros only the elements below the k
subdiagonal of m.
Details and Options
- UpperTriangularize[m] works even if m is not a square matrix.
- In UpperTriangularize[m,k], positive k refers to subdiagonals above the main diagonal and negative k refers to subdiagonals below the main diagonal.
- UpperTriangularize works with SparseArray objects.
- UpperTriangularize[…,TargetStructure->struct] returns the upper triangular matrix in the format specified by struct. Possible settings include:
-
Automatic automatically choose the representation returned "Dense" represent the matrix as a dense matrix "Sparse" represent the matrix as a sparse array "Structured" represent the matrix as an UpperTriangularMatrix - With UpperTriangularize[…,TargetStructureAutomatic], the structure of the resulting upper triangular matrix is the same as that of the original matrix, if the original matrix is a dense matrix, a sparse array, a structured DiagonalMatrix or a structured UpperTriangularMatrix. Otherwise, a dense matrix is returned.
Examples
open all close allBasic Examples (3)
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]]Get the upper triangular part of a matrix plus the diagonal below the main diagonal:
MatrixForm[UpperTriangularize[{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, -1]]Scope (12)
Basic Uses (8)
Get the upper triangular part of non-square 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}}]]Find the upper triangular part of a machine-precision matrix:
UpperTriangularize[{{1.25, 3.2, 3.2}, {7.9, -1.4, 5.1}, {1., -1.5, 3.2}}]//MatrixFormUpper triangular part of a complex matrix:
UpperTriangularize[{{1. + I, 2, 3 - 2 I}, {0, 4, 5I}, {1 + I, 6, 3 + 3I}}]//MatrixFormUpper triangular part of an exact matrix:
UpperTriangularize[{{2, 3}, {3, 1}, {2, 4}, {2, 3}}]//MatrixFormUpper triangular part of an arbitrary-precision matrix:
UpperTriangularize[RandomReal[4, {2, 2}, WorkingPrecision -> 20]]//MatrixFormCompute the upper triangular part of a symbolic matrix:
UpperTriangularize[{{a, b, c, d}, {e, f, g, h}}]//MatrixFormLarge matrices are handled efficiently:
mat = RandomReal[{0, 10}, {800, 800}];UpperTriangularize[mat]; //TimingThe 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, -4, 3}]Special Matrices (4)
The upper triangular part of a sparse matrix is returned as a sparse matrix:
SparseArray[{{1, 3} -> 1, {2, 2} -> 2, {3, 1} -> 3}, {3, 4}]UpperTriangularize[%]%//MatrixFormThe upper triangular part of structured matrices:
SymmetrizedArray[{{1, 1} -> 3, {2, 2} -> 1, {3, 1} -> -5}, {3, 3}, Symmetric[All]]UpperTriangularize[%]QuantityArray[{{1, 2}, {3, 4}, {5, 6}}, {"Meters", "Seconds"}]UpperTriangularize[%, 1]The upper triangular part of an identity matrix is the matrix itself:
UpperTriangularize[IdentityMatrix[3]]This is true of any diagonal matrix:
UpperTriangularize[DiagonalMatrix[{1, 2, 3}]]//MatrixFormCompute the upper triangular part, including the subdiagonal, for HilbertMatrix:
UpperTriangularize[HilbertMatrix[{3, 4}], -1]//MatrixFormOptions (2)
TargetStructure (2)
m = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};Return the result as a dense matrix:
UpperTriangularize[m, TargetStructure -> "Dense"]Return the result as a sparse matrix:
UpperTriangularize[m, TargetStructure -> "Sparse"]Return the result as an UpperTriangularMatrix:
UpperTriangularize[m, TargetStructure -> "Structured"]sa = SparseArray[{{1, 3} -> 1, {2, 2} -> 2, {3, 1} -> 3}, {3, 3}]The setting TargetStructureAutomatic gives a sparse result:
UpperTriangularize[sa, TargetStructure -> Automatic]Convert the sparse array to a dense matrix:
dsa = Normal[sa, SparseArray]The setting TargetStructureAutomatic gives a dense result:
UpperTriangularize[dsa, TargetStructure -> Automatic]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:
{UpperTriangularize[t] == t, UpperTriangularize[t, -1] == t}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:
{UpperTriangularize[j] == j, m == s.j.Inverse[s]}The matrix
is diagonalizable iff its Jordan matrix
is also lower triangular:
{LowerTriangularize[j] == j, DiagonalizableMatrixQ[m]}Properties & Relations (11)
Matrices returned by UpperTriangularize satisfy UpperTriangularMatrixQ:
UpperTriangularMatrixQ[UpperTriangularize[{{a, b}, {c, d}}]]UpperTriangularMatrixQ[UpperTriangularize[{{a, b}, {c, d}}, 1], 1]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}]];Det[m] == Apply[Times, Diagonal[m]]Eigenvalues of a triangular matrix equal its diagonal elements:
m = UpperTriangularize[RandomReal[1., {5, 5}]];Eigenvalues[m] == Reverse@Sort@Diagonal[m]QRDecomposition gives an upper triangular matrix:
{q, r} = QRDecomposition[RandomReal[1., {5, 5}]];UpperTriangularize[r] == rCholeskyDecomposition gives an upper triangular matrix:
CholeskyDecomposition[{{2, 1}, {1, 2}}]UpperTriangularize[%] == %JordanDecomposition gives an upper triangular matrix:
{s, j} = JordanDecomposition[RandomReal[1., {5, 5}]];UpperTriangularize[j] == jHessenbergDecomposition returns a matrix that is upper triangular with an added subdiagonal:
{p, h} = HessenbergDecomposition[RandomReal[1., {5, 5}]];UpperTriangularMatrixQ[h, -1]HermiteDecomposition gives an upper triangular matrix:
{u, r} = HermiteDecomposition[{{1, 2, 3}, {5, 4, 3}, {8, 7, 9}}];UpperTriangularize[r] == rUpperTriangularize[m,k] is equivalent to Transpose[LowerTriangularize[Transpose[m],-k]]:
m = RandomReal[1, {3, 5}];
k = RandomInteger[{-2, 4}];
{MatrixForm[u = UpperTriangularize[m, k]], u === Transpose[LowerTriangularize[Transpose[m], -k]]}Related Guides
Text
Wolfram Research (2008), UpperTriangularize, Wolfram Language function, https://reference.wolfram.com/language/ref/UpperTriangularize.html (updated 2023).
CMS
Wolfram Language. 2008. "UpperTriangularize." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2023. https://reference.wolfram.com/language/ref/UpperTriangularize.html.
APA
Wolfram Language. (2008). UpperTriangularize. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/UpperTriangularize.html
BibTeX
@misc{reference.wolfram_2026_uppertriangularize, author="Wolfram Research", title="{UpperTriangularize}", year="2023", howpublished="\url{https://reference.wolfram.com/language/ref/UpperTriangularize.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_uppertriangularize, organization={Wolfram Research}, title={UpperTriangularize}, year={2023}, url={https://reference.wolfram.com/language/ref/UpperTriangularize.html}, note=[Accessed: 12-June-2026]}