# isdiag

isdiag(A) -> Bool

Test whether a matrix is diagonal.

## Examples

1. Check if a matrix is diagonal:

``````julia> A = [1 0 0; 0 2 0; 0 0 3];
julia> isdiag(A)
true``````

This example checks if the matrix `A` is diagonal. In this case, it returns `true` because all the off-diagonal elements are zero.

2. Handle non-diagonal matrices:

``````julia> B = [1 2 3; 4 5 6; 7 8 9];
julia> isdiag(B)
false``````

It returns `false` because the matrix `B` has non-zero elements outside the diagonal.

3. Check if a square matrix is empty:
``````julia> C = zeros(0, 0);
julia> isdiag(C)
true``````

It correctly handles the case when the square matrix `C` is empty, and returns `true` since there are no off-diagonal elements to consider.

Common mistake example:

``````julia> D = [1 0; 0 2; 0 0];
julia> isdiag(D)
ERROR: DimensionMismatch("matrix must be square")``````

In this example, the matrix `D` provided is not square, resulting in a `DimensionMismatch` error. Ensure that the matrix passed to `isdiag` is a square matrix to avoid this error.