Skip to content

Matrix Predicates

SID37 edited this page Nov 17, 2019 · 2 revisions

antisymmetric?()

Returns true if this is an antisymmetric matrix. Raises an error if matrix is not square.

m = Matrix[
    [ 0, 1, -3],
    [-1, 0, -5],
    [ 3, 5,  0]]
m.antisymmetric?
# => true

diagonal?()

Returns true if this is a diagonal matrix. Raises an error if matrix is not square.

m = Matrix[[2, 0, 0], [0, 3, 0], [0, 0, 5]]
m.diagonal?
# => true

empty?()

Returns true if this is an empty matrix, but our matrix is never empty. So it always returns false.

hermitian?()

Alias for: symmetric?. Implemented just for compatibility with standard matrix.

lower_triangular?()

Returns true if this is a lower triangular matrix.

m = Matrix[[1, 0, 0], [1, 2, 0], [3, 3, 3]]
m.lower_triangular?
# => true

upper_triangular?()

Returns true if this is an upper triangular matrix.

m = Matrix[[1, 2, 3], [0, 2, 3], [0, 0, 4]]
m.upper_triangular?
# => true

normal?()

Returns true if this is a normal matrix. Raises an error if matrix is not square.

Remember that our matrix does not support complex numbers!

m = Matrix[[1, 1, 0], [0, 1, 1], [1, 0, 1]]
m.normal?
# => true

orthogonal?()

Returns true if this is an orthogonal matrix Raises an error if matrix is not square.

m = Matrix[[0.96, -0.28], [0.28, 0.96]]
m.orthogonal?
# => true

permutation?()

Returns true if this is a permutation matrix Raises an error if matrix is not square.

m = Matrix[[0, 1, 0], [1, 0, 0], [0, 0, 1]]
m.permutation?
# => true

regular?()

Returns true if this is a regular (i.e. non-singular) matrix.

m = Matrix[[1, 0], [0, 1]]
m.singular?
# => true
m = Matrix[[0, 1], [0, 1]]
m.singular?
# => false

singular?()

Returns true if this is a singular matrix.

m = Matrix[[1, 2], [2, 4]]
m.singular?
# => true
m = Matrix[[1, 2], [3, 4]]
m.singular?
# => false

skew_symmetric?()

Alias for: antisymmetric?

square?()

Returns true if this is a square matrix.

m = Matrix[[1, 2], [3, 4]]
m.square?
# => true
m = Matrix[[1, 2], [3, 4], [5, 6]]
m.square?
# => false

symmetric?()

Returns true if this is a symmetric matrix. Raises an error if matrix is not square.

m = Matrix[
    [1, 2, 3], 
    [2, 4, 5]
    [3, 5, 6]]
m.symmetric?
# => true

unitary?()

Returns true if this is a unitary matrix. Raises an error if matrix is not square.

Remember that our matrix does not support complex numbers!

m = Matrix[[0, 1], [1, 0]]
m.unitary?
# => true

zero?()

Returns true if this is a matrix with only zero elements.

m = Matrix[[0, 0], [0, 0]]
m.zero?
# => true

real?()

Always return true. Implemented just for compatibility with standard matrix.