Main Content

triu

Return upper triangular part of symbolic matrix

Description

triu(A) returns a triangular matrix that retains the upper part of the matrix A. The lower triangle of the resulting matrix is padded with zeros.

triu(A,k) returns a matrix that retains the elements of A on and above the k-th diagonal. The elements below the k-th diagonal equal to zero. The values k = 0, k > 0, and k < 0 correspond to the main, superdiagonals, and subdiagonals, respectively.

Examples

Upper Triangular Part of Symbolic Matrix

Display the matrix retaining only the upper triangle of the original symbolic matrix:

syms a b c
A = [a b c; 1 2 3; a + 1 b + 2 c + 3];
triu(A)
ans =
[ a, b,     c]
[ 0, 2,     3]
[ 0, 0, c + 3]

Triangular Matrix On and Above Specified Superdiagonal

Display the matrix that retains the elements of the original symbolic matrix on and above the first superdiagonal:

syms a b c
A = [a b c; 1 2 3; a + 1 b + 2 c + 3];
triu(A, 1)
ans =
[ 0, b, c]
[ 0, 0, 3]
[ 0, 0, 0]

Triangular Matrix On and Above Specified Subdiagonal

Display the matrix that retains the elements of the original symbolic matrix on and above the first subdiagonal:

syms a b c
A = [a b c; 1 2 3; a + 1 b + 2 c + 3];
triu(A, -1)
ans =
[ a,     b,     c]
[ 1,     2,     3]
[ 0, b + 2, c + 3]

Input Arguments

collapse all

Input, specified as a numeric or symbolic matrix.

Diagonal, specified as a numeric or symbolic number.

Version History

Introduced before R2006a

See Also

|