# triu!(M)

triu!(M)

Upper triangle of a matrix, overwriting `M` in the process.

## Examples

1. Modify a matrix by keeping only the upper triangle:

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

This example modifies the matrix `A` by keeping only the upper triangle elements.

2. Specify the superdiagonal to start from:

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

Here, the `k` value is set to 1, which means the upper triangle starts from the first superdiagonal.

3. Handle edge cases with empty matrices:
``````julia> C = Int64[]
julia> triu!(C)
0-element Array{Int64,1}``````

It correctly handles the case when the input matrix is empty.

Common mistake example:

``````julia> D = [1 2; 3 4; 5 6];
julia> triu!(D, 5)
ERROR: BoundsError: attempt to access 3×2 Matrix{Int64} at index [3, 4]``````

In this example, the value of `k` provided is greater than the number of superdiagonals in the matrix `D`. It's important to ensure that `k` is within a valid range to avoid such errors. Always check the dimensions of the matrix before using `triu!`.