How to speed up function evaluation by vectorization
Ältere Kommentare anzeigen
Is there a way to speed up this code significantly? Maybe by more vectorization?
It is the evaluation of a Hesse matrix. The first loop is a "dot product" between basis elements in the form of 16x16 matrices (Lambda) and corresponding coefficients (T). The second (double-) loop is the evaluation of the Hesse matrix itself.
This is a more generic version of the code:
Hesse=eye(256,256);
B=rand(1296,256);
T=rand(256,1);
Lambda=rand(16,16,256);
f=rand(1296,1);
P_int=B*T;
rho_int=zeros(16);
%Loop 1
for j=1:256
rho_int=rho_int+T(j,1)*Lambda(:,:,j)/2^4;
end
rho_int_inv=inv(rho_int);
%Loop 2
for k=2:256
for l=2:256
Hesse(k,l)=dot(f, (B(:,k).*B(:,l))./(P_int.^2))+trace(rho_int_inv*Lambda(:,:,k)*rho_int_inv*Lambda(:,:,l)/4^4);
end
end
2 Kommentare
Andrei Bobrov
am 7 Okt. 2015
P_int - what is it?
Frederik Lohof
am 7 Okt. 2015
Bearbeitet: Frederik Lohof
am 7 Okt. 2015
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Quantum Mechanics finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!