Efficient Matrix Multiplication

1 回表示 (過去 30 日間)
Sam Da
Sam Da 2011 年 2 月 26 日
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 件のコメント
the cyclist
the cyclist 2011 年 2 月 26 日
From his initialization step, I would infer that "AA" is just a typo of "A."
Jan
Jan 2011 年 2 月 27 日
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.

サインインしてコメントする。

採用された回答

the cyclist
the cyclist 2011 年 2 月 26 日
P1 = A * A';
On my machine, that cut the execution time from 330 seconds to 1.5. :-)
  3 件のコメント
Oleg Komarov
Oleg Komarov 2011 年 2 月 26 日
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.
James Tursa
James Tursa 2011 年 2 月 26 日
Yep. I went back & checked the code I used to double check the result & saw my mistake. Thanks.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by