Multiplying Vectors by a Matrix Entry-wise

  • Thread starter Thread starter jemma
  • Start date Start date
  • Tags Tags
    Matrix Vectors
AI Thread Summary
The discussion revolves around performing entry-wise multiplication of vectors and a matrix in a mathematical context. The user seeks to multiply a row vector 'a' and a column vector 'b' with a matrix 'c' to produce a resulting matrix 'd'. Initially, there is confusion regarding the dimensions of the vectors and the matrix, as direct entry-wise multiplication requires matching dimensions. Clarification is provided that the intended operation involves multiplying each entry of 'c' by corresponding entries of 'a' and 'b'. A solution is proposed by replicating the vectors 'a' and 'b' to match the dimensions of 'c', allowing for successful entry-wise multiplication. The final expression provided demonstrates how to achieve the desired result by adjusting the dimensions appropriately.
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
 
Back
Top