diff --git a/lib/matrix.rb b/lib/matrix.rb index 6853be8..8f57c73 100644 --- a/lib/matrix.rb +++ b/lib/matrix.rb @@ -614,7 +614,7 @@ class Matrix # def hermitian? Matrix.Raise ErrDimensionMismatch unless square? - each_with_index(:strict_upper).all? do |e, row, col| + each_with_index(:upper).all? do |e, row, col| e == rows[col][row].conj end end diff --git a/test/matrix/test_matrix.rb b/test/matrix/test_matrix.rb index 26248e5..2f48f35 100644 --- a/test/matrix/test_matrix.rb +++ b/test/matrix/test_matrix.rb @@ -246,6 +246,19 @@ class TestMatrix < Test::Unit::TestCase assert_raise(ArgumentError) { @m1.minor(0) } end + def test_hermitian? + i = Complex::I + assert(Matrix[[-2, -3-i, 3+i ], + [-3+i, 3, -5-7*i], + [ 3-i, -5+7*i, 9 ]].hermitian?) + assert(!Matrix[[-2, -3-i, 3+i ], + [-3+i, 3, 4-8*i], + [ 3-i, 4-8*i, 9 ]].hermitian?) + assert(!Matrix[[-2, -3-i, 3+i ], + [-3+i, 3, -5-7*i], + [ 3-i, -5+7*i, 9-4*i]].hermitian?) + end + def test_regular? assert(Matrix[[1, 0], [0, 1]].regular?) assert(Matrix[[1, 0, 0], [0, 1, 0], [0, 0, 1]].regular?)