Reduce computation time in the for-loop

1 回表示 (過去 30 日間)
Jeongseop Lee
Jeongseop Lee 2018 年 9 月 5 日
コメント済み: dpb 2018 年 9 月 5 日
Hi all,
I have three "n-by-n" matrices and one "m-by-4*n" matrix. A for-loop is used to compute a scalar for each row in X for all m and stores them in a m-by-1 matrix in the following manner.
% declare variables for this particular example with random parameters.
n = 100; m = 100; D = zeros(m,1);
A = random('norm',0,1,[n,n]);
B = random('norm',0,1,[n,n]);
C = random('norm',0,1,[n,n]);
X = random('norm',0,1,[m,4*n]);
for i = 1 : m
D(i)=X(i,3*n+1:4*n)*A*toeplitz(X(i,1:n))*B*toeplitz(X(i,n+1:2*n))*X(i,2*n+1:3*n)';
end
Typically my n and m are around 1e3 and I have to iterate this for-loop about 1e6 times for topological optimization so the computation takes quite a bit of time. One way I see forward is to to calculate D without the for-loop somehow. Any suggestions as to how to proceed with this?
Thanks,
  1 件のコメント
dpb
dpb 2018 年 9 月 5 日
At the purely mechanistic it appears would just be replacing an explicit for loop with arrayfun that likely woudn't be as fast, anyway.
I'm guessing the only way would be to sit down with paper/pencil and see if can do something with the algebra to reduce it somehow. In the real case are there any patterns that can exploit; if everything is random as here, that pretty-much negates that, too.

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with Optimization Toolbox についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by