Make this matrix multiplication more efficient
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello,
I would like to do the following matrix multiplication much efficiently:
m=1000;n=500;
a=zeros(n,1);
b=rand(n,1);
A=rand(m,n);
B=rand(m,m);
for i=1:n
a(i)=b'*(A'*B(i,:)'*B(i,:)*A)*b;
end
Thanks in advance
댓글 수: 0
채택된 답변
James Tursa
2015년 11월 25일
a = (B(1:n,:)*(A*b)).^2;
You dimensions for B look a little strange to me, since your calculations do not use all of the rows of B (hence the B(1:n,:) reduction above).
추가 답변 (1개)
Richa Gupta
2015년 11월 25일
Hi Ignacio,
The code below reduces the time from 2.6 secs to 0.06 secs on my machine:
m = 1000; n = 500;
a = zeros(n,1);
b = rand(n,1);
A = rand(m,n);
B = rand(m,m);
for i=1:n
temp =(B(i,:)*A)*b;
a(i) = temp'*temp;
end
Hope this helps.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!