Matrix .* vector?

  • Thread starter jemma
  • Start date
  • #1
jemma
36
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!
 

Answers and Replies

  • #2
mikeph
1,234
18
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.
 
  • #3
jemma
36
0
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:
  • #4
matonski
166
0
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
 

Suggested for: Matrix .* vector?

Replies
4
Views
2K
Replies
1
Views
3K
  • Last Post
Replies
1
Views
2K
  • Last Post
Replies
2
Views
7K
  • Last Post
Replies
2
Views
10K
Replies
5
Views
4K
Replies
2
Views
11K
  • Last Post
Replies
5
Views
4K
  • Last Post
Replies
1
Views
3K
Top