triu(M)

triu(M)

Upper triangle of a matrix.

Examples

julia> M = [1 2 3; 4 5 6; 7 8 9];
julia> triu(M, 1)
3×3 Array{Int64,2}:
 0  2  3
 0  0  6
 0  0  0

This example returns the upper triangle of matrix M starting from the first superdiagonal.

julia> A = [1 2 3; 4 5 6; 7 8 9];
julia> triu(A, -1)
3×3 Array{Int64,2}:
 1  2  3
 4  5  6
 0  8  9

Here, the upper triangle of matrix A starting from the -1st superdiagonal is returned.

julia> B = [10 20 30; 40 50 60; 70 80 90];
julia> triu(B)
3×3 Array{Int64,2}:
 10  20  30
  0  50  60
  0   0  90

In this example, the default behavior of triu is shown, which starts from the main diagonal.

Common mistake example:

julia> C = [1 2 3; 4 5 6; 7 8 9];
julia> triu(C, 4)
ERROR: BoundsError: attempt to access 3×3 Array{Int64,2} at index [4, 4]

In this case, the value of k provided is greater than the number of superdiagonals available in the matrix C. Make sure to use a valid value for k to avoid such errors.

See Also

Ac_ldiv_B, Ac_ldiv_Bc, Ac_mul_B, Ac_mul_Bc, Ac_rdiv_B, Ac_rdiv_Bc, At_ldiv_B, At_ldiv_Bt, At_mul_B, At_mul_Bt, At_rdiv_B, At_rdiv_Bt, A_ldiv_Bc, A_ldiv_Bt, A_mul_B!, A_mul_Bc, A_mul_Bt, A_rdiv_Bc, A_rdiv_Bt, Bidiagonal, cond, conv2, det, diag, diagind, diagm, diff, eig, eigvals, eigvecs, expm, eye, full, inv, isdiag, ishermitian, isposdef, isposdef!, issym, istril, istriu, logabsdet, logdet, lyap, norm, qrfact, rank, repmat, rot180, rotl90, rotr90, sortrows, sqrtm, SymTridiagonal, trace, Tridiagonal, tril, tril!, triu, triu!, writedlm,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: