Efficient Matrix Multiplication

I have A(2000x5000). I need to perform the following:
P1 = A(:,1)*A(:,1)';
for i=2:5000
P1 = P1 + AA(:,i)*A(:,i)'
end
What is the most efficient way to do above? It takes so much time to do it right now due to size of the arrays.

3 个评论

What is AA in this?
From his initialization step, I would infer that "AA" is just a typo of "A."
Just an actually too obvious comment: If AA is not typo, A*A' is not a matching solution. So, Sam Da, we need your help.

请先登录,再进行评论。

 采纳的回答

P1 = A * A';
On my machine, that cut the execution time from 330 seconds to 1.5. :-)

3 个评论

Except that does not do the same calculation. The loop in OP's post above only does the outer product of each column with itself, not the entire A*A' product.
A = rand(10);
P1 = A(:,1)*A(:,1)';
for i=2:10
P1 = P1 + A(:,i)*A(:,i)';
end
P2 = A * A';
abs(P1-P2) < eps*3
Cyclist's method is essentially the same.
Yep. I went back & checked the code I used to double check the result & saw my mistake. Thanks.

请先登录,再进行评论。

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by