mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/matrix] Fix Matrix#orthogonal?
This commit is contained in:
parent
7d360efe92
commit
3cb038cc7a
2 changed files with 11 additions and 3 deletions
|
@ -890,11 +890,12 @@ class Matrix
|
||||||
#
|
#
|
||||||
def orthogonal?
|
def orthogonal?
|
||||||
raise ErrDimensionMismatch unless square?
|
raise ErrDimensionMismatch unless square?
|
||||||
rows.each_with_index do |row, i|
|
|
||||||
column_count.times do |j|
|
rows.each_with_index do |row_i, i|
|
||||||
|
rows.each_with_index do |row_j, j|
|
||||||
s = 0
|
s = 0
|
||||||
row_count.times do |k|
|
row_count.times do |k|
|
||||||
s += row[k] * rows[k][j]
|
s += row_i[k] * row_j[k]
|
||||||
end
|
end
|
||||||
return false unless s == (i == j ? 1 : 0)
|
return false unless s == (i == j ? 1 : 0)
|
||||||
end
|
end
|
||||||
|
|
|
@ -800,4 +800,11 @@ class TestMatrix < Test::Unit::TestCase
|
||||||
assert_equal false, @a3.unitary?
|
assert_equal false, @a3.unitary?
|
||||||
assert_raise(Matrix::ErrDimensionMismatch) { @m1.unitary? }
|
assert_raise(Matrix::ErrDimensionMismatch) { @m1.unitary? }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_orthogonal
|
||||||
|
assert_equal true, @rot.orthogonal?
|
||||||
|
assert_equal false, ((0+1i) * @rot).orthogonal?
|
||||||
|
assert_equal false, @a3.orthogonal?
|
||||||
|
assert_raise(Matrix::ErrDimensionMismatch) { @m1.orthogonal? }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue