stdlib/matrix.rb
#
# Returns +true+ if this is a unitary matrix
# Raises an error if matrix is not square.
#
Returns +true+ if this is a unitary matrix
Raises an error if matrix is not square.
Returns + true + if this is a unitary matrix Raises an error if matrix is not square .
def unitary?
    Matrix.Raise ErrDimensionMismatch unless square?
    rows.each_with_index do |row, i|
      column_count.times do |j|
        s = 0
        row_count.times do |k|
          s += row[k].conj * rows[k][j]
        end
        return false unless s == (i == j ? 1 : 0)
      end
    end
    true
  end
def unitary? Matrix . Raise ErrDimensionMismatch unless square? rows . each_with_index do | row , i | column_count . times do | j | s = 0 row_count . times do | k | s += row [ k ] . conj * rows [ k ] [ j ] end return false unless s == ( i == j ? 1 : 0 ) end end true end
Returns +true+ if this is a unitary matrix
Raises an error if matrix is not square.
Returns + true + if this is a unitary matrix Raises an error if matrix is not square .