Method: Matrix#unitary?

Defined in:
lib/matrix.rb

#unitary?Boolean

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

Returns:

  • (Boolean)

Raises:



986
987
988
989
990
991
992
993
994
995
996
997
998
# File 'lib/matrix.rb', line 986

def unitary?
  raise ErrDimensionMismatch unless square?
  rows.each_with_index do |row_i, i|
    rows.each_with_index do |row_j, j|
      s = 0
      row_count.times do |k|
        s += row_i[k].conj * row_j[k]
      end
      return false unless s == (i == j ? 1 : 0)
    end
  end
  true
end