Multiplying Vectors by a Matrix Entry-wise

  • Thread starter Thread starter jemma
  • Start date Start date
  • Tags Tags
    Matrix Vectors
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
3 replies · 3K views
jemma
Messages
35
Reaction score
0
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!
 
Physics news on Phys.org
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.
 
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:
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