diff --git a/NEWS b/NEWS index 798c881..112fb0e 100644 --- a/NEWS +++ b/NEWS @@ -61,6 +61,10 @@ with all sufficient information, see the ChangeLog file. which is obtained by multiplying the first minor by (-1)**(row + column). * Matrix#@+ and Matrix#@- . +* Vector + * New methods: + * Vector#@+ and Vector#@- . + * Method * New methods: * Method#curry([arity]) returns a curried Proc. diff --git a/lib/matrix.rb b/lib/matrix.rb index 6fa1a42..b74e5f2 100644 --- a/lib/matrix.rb +++ b/lib/matrix.rb @@ -1574,6 +1574,7 @@ end # * #+(v) # * #-(v) # * #+@ +# * #-@ # # Vector functions: # * #inner_product(v) @@ -1802,6 +1803,10 @@ class Vector self end + def -@ + collect {|e| -e } + end + #-- # VECTOR FUNCTIONS -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- #++ diff --git a/test/matrix/test_vector.rb b/test/matrix/test_vector.rb index fc3aa15..337aaa8 100644 --- a/test/matrix/test_vector.rb +++ b/test/matrix/test_vector.rb @@ -115,6 +115,11 @@ class TestVector < Test::Unit::TestCase assert_equal(@v1, +@v1) end + def test_negate + assert_equal(Vector[-1, -2, -3], -@v1) + assert_equal(@v1, -(-@v1)) + end + def test_inner_product assert_equal(1+4+9, @v1.inner_product(@v1)) end