# 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.