replacing for loop with more efficient code
Ältere Kommentare anzeigen
Hi, given symmetric matrices für i=1,...,m, positiv definite and symmetric and ,
I want to compute with .
I solved this with the following for loop:
for i=1:m
M_row=X*A(:,(i-1)*n+1:i*n)*inv_S;
for j=i:m %since M is symmetric
M(i,j)=trace(M_row*A(:,(j-1)*n+1:j*n));
end
end
Is there a more efficient way to solve this in matlab? with vectorization?
2 Kommentare
Bruno Luong
am 11 Jan. 2019
OP wants to compute
M(i,j) = Trace(X * A(:,:,i) * inv(S) * A(:,:,j))
where A(:,:,i), X and S are n x n symmetric, matrices, S and X are definite positive. i=1,...m
His original code that needs to be optimized is
M = zeros(m,m);
inv_S = inv(S);
for i=1:m
M_row=X*A(:,(i-1)*n+1:i*n)*inv_S;
for j=i:m %since M is symmetric
M(i,j)=trace(M_row*A(:,(j-1)*n+1:j*n));
end
end
Anusha Sridharan
am 11 Jan. 2019
[Answers Dev] Restored Edits
Akzeptierte Antwort
Weitere Antworten (1)
Lukas Müller
am 10 Jan. 2019
0 Stimmen
Kategorien
Mehr zu Programming finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!