help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: subtraction of vectors results in 0 [bug?]


From: Nicholas Jankowski
Subject: Re: subtraction of vectors results in 0 [bug?]
Date: Mon, 30 Nov 2015 09:58:46 -0500

On Mon, Nov 30, 2015 at 9:50 AM, Jonathan Camilleri <address@hidden> wrote:
I am not sure if this is correct.

v
v =

   1   0
   1   1
   2   4

>> x
x =

   1   0
   1   1
   2   4

>> ans = v-x
ans =

   0   0
   0   0
   0   0

error: operator *: nonconformant arguments (op1 is 3x2, op2 is 3x2)

I do not have access to the bug tracker.

--
Jonathan Camilleri

Mobile (MT): ++356 7982 7113
E-mail: address@hidden
Please consider your environmental responsibility before printing this e-mail.
 

no bug.  this is how vector/matrix addition and subtraction is supposed to work. v(i,j) - x(i,j) = ans(i,j)

more of an issue is how you got a nonconformant argument error.  You didn't show any usage of the * operator to create that error message.  it looks like the error you should get if you tried:

>> x*v
error: operator *: nonconformant arguments (op1 is 3x2, op2 is 3x2)

because * is for matrix multiplication, which has very specific size requirements. See:
https://en.wikipedia.org/wiki/Matrix_multiplication

If you want to multiply the elements, you have to use the element-wise multiplication operator .*

>> x.*v
ans =

    1    0
    1    1
    4   16



reply via email to

[Prev in Thread] Current Thread [Next in Thread]