Hi, thank you for the prompt response!
The problem I want to apply this for is simulation of magnetic resonance spectra. Basically the matrices are functions of a magnetic field B, and I have to find the values B0 for which energy (eigenvalue) differences in the energy matrix match a certain value (microwave frequency). Finding of the values B0 is done adaptively, by dividing the interval [Bmin,Bmax] in halfs, and finding by approximation the solutions. My algorithm is probably very far from efficient at this point, but I estimate I need to diagonalize tens of matrices per cycle of the adaptive scheme.
It is highly possible that the actual diagonalization is not the time consuming part, but then the short loops I run to find the eigenvalue differences are what is slowing everything down. I should rethink the whole thing.
Anyway, below I send the code for the small benchmark I made. Perhaps there is a much faster way of doing this.
Thank you very much!
Best,
Nicolas
%begin
clear all, close all
more off
disp(['Size of each matrix: ',' Number of matrices: ',' Loop to block ratio: ']);
for pMatSize = [2,4,8,16,32,64,128]
for nMat = 2:20
SizeMatrices = pMatSize;
Nmatrices = nMat;
eigA = zeros(SizeMatrices,Nmatrices);
timeLoop = zeros(Nmatrices,1);
augA = cell(Nmatrices,1);
for k = 1:Nmatrices
tmpA = rand(SizeMatrices,SizeMatrices);
augA{k} = tmpA'*tmpA;
end
tic
for k = 1:Nmatrices
eigA(:,k) = eig(augA{k});
end
timeLoop = toc;
augAmat = blkdiag(augA{:});
tic
eigaugA = eig(augAmat);
timeBlock = toc;
disp([num2str(SizeMatrices) ' ' num2str(Nmatrices) ' ' num2str(timeLoop/timeBlock)]);
end
end
%end