Reduce computation time in the for-loop

1 visualizzazione (ultimi 30 giorni)
Jeongseop Lee
Jeongseop Lee il 5 Set 2018
Commentato: dpb il 5 Set 2018
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 Commento
dpb
dpb il 5 Set 2018
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.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Get Started with Optimization Toolbox in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by