1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/matrix] Add Matrix#adjoint [#14]

Patch adapted from Alessandro Minali
This commit is contained in:
Marc-Andre Lafortune 2020-04-30 18:04:30 -04:00
parent 07fd6dc49b
commit 9b5675b325
2 changed files with 16 additions and 0 deletions

View file

@ -1532,6 +1532,17 @@ class Matrix
end
alias_method :conj, :conjugate
#
# Returns the adjoint of the matrix.
#
# Matrix[ [i,1],[2,-i] ].adjoint
# # => -i 2
# # 1 i
#
def adjoint
conjugate.transpose
end
#
# Returns the imaginary part of the matrix.
# Matrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]]

View file

@ -807,4 +807,9 @@ class TestMatrix < Test::Unit::TestCase
assert_equal false, @a3.orthogonal?
assert_raise(Matrix::ErrDimensionMismatch) { @m1.orthogonal? }
end
def test_adjoint
assert_equal(Matrix[[(1-2i), 1], [(0-1i), 2], [0, 3]], @c1.adjoint)
assert_equal(Matrix.empty(0,2), @e1.adjoint)
end
end