Vector and matrices dotwise multiplication

조회 수: 1 (최근 30일)
Piment
Piment 2013년 4월 8일
I have a n elements vector a1 a2 ... an
and n same-sized matrices b1 b2 ... bn
how can I do a1*b1 + a2*b2 + ... + an*bn without loop? I was thinking if there's a way to do something like multidimentsional array dotwise multiplication? Thanks.

답변 (1개)

per isakson
per isakson 2013년 4월 8일
Try
a * transpose( b )
where
a = [ a1, a2, ... an ]
b = [ b1, b2, ... bn ]
  댓글 수: 1
Piment
Piment 2013년 4월 13일
편집: Piment 2013년 4월 13일
I'm not sure if I have made it clear enough, the thing is it's not gonna work because I've tried this before. this is what I did and what matlab spitted out:
>> a = [rand(1), rand(1), rand(1), rand(1)];
>> [b1, b2, b3, b4] = deal(magic(3));
>> b = [b1, b2, b3, b4];
>> a * transpose(b);
Error using *
Inner matrix dimensions must agree.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by