Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matrix .* vector?

  1. Mar 23, 2010 #1
    Hi, this is probably a really simple problem but I'm trying to multiply vectors by a matrix, using entry-wise multiplication.
    For example, I want to do something like this:

    a = [1 2 3 4]
    b = [5 6 7 8]'
    c = [1 2 3 4; 5 6 7 8; 9 10 11 12; 13 14 15 16]

    d = a.*b.*c

    So that d is a 4x4 matrix and for example:

    d(1,2) = 1*5*1 (etc.) So that each entry in the first row of d will be multiplied by b(1) and the corresponding a entry. Does this make sense? Anyway, is this possible?

    Thanks!
     
  2. jcsd
  3. Mar 23, 2010 #2
    To use entry-wise multiplication the matrix dimensions must be the same, which they are not. a.*b is a 1x4 matrix and c is a 4x4 matrix.



    I don't understand your second to last line because you seem to be explaining how to find d(1,2) by describing an operation on d itself.
     
  4. Mar 23, 2010 #3
    Sorry, I meant to say, for example,
    d(1,1) = a(1) .* b(1) .* c(1)
    and,
    d(1,2) = a(2) .* b(1) .* c(2)

    I basically want to multiply each entry of every row of 'c' by 'b' then each entry of every column of 'c' by 'a'.
    So isn't this possible since the dimentions are different?

    I guess just making
    a=[1 2 3 4; 1 2 3 4; 1 2 3 4; 1 2 3 4]
    and
    b=[5 6 7 8; 5 6 7 8; 5 6 7 8; 5 6 7 8]'
    Then d = a.*b.*c works OK.
     
    Last edited: Mar 23, 2010
  5. Apr 2, 2010 #4
    a = [1 2 3 4]
    b = [5 6 7 8]'
    c = [1 2 3 4; 5 6 7 8; 9 10 11 12; 13 14 15 16]
    b*a.*c
     
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook