diff --git a/NEWS b/NEWS index b85aed1..798c881 100644 --- a/NEWS +++ b/NEWS @@ -59,6 +59,7 @@ with all sufficient information, see the ChangeLog file. by deleting the specified row and column. * Matrix#cofactor(row, column) returns the (row, column) cofactor which is obtained by multiplying the first minor by (-1)**(row + column). + * Matrix#@+ and Matrix#@- . * Method * New methods: diff --git a/lib/matrix.rb b/lib/matrix.rb index ee5a716..fe76ca0 100644 --- a/lib/matrix.rb +++ b/lib/matrix.rb @@ -87,6 +87,7 @@ end # * #inv # * #** # * #+@ +# * #-@ # # Matrix functions: # * #determinant @@ -1045,6 +1046,10 @@ class Matrix self end + def -@ + collect {|e| -e } + end + #-- # MATRIX FUNCTIONS -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- #++ diff --git a/test/matrix/test_matrix.rb b/test/matrix/test_matrix.rb index 13ffbb8..d6a420b 100644 --- a/test/matrix/test_matrix.rb +++ b/test/matrix/test_matrix.rb @@ -61,6 +61,11 @@ class TestMatrix < Test::Unit::TestCase assert_equal(@m1, +@m1) end + def test_negate + assert_equal(Matrix[[-1, -2, -3], [-4, -5, -6]], -@m1) + assert_equal(@m1, -(-@m1)) + end + def test_rank [ [[0]],