I hope, a good answer will help understanding of how to use MATLAB in a truly efficient way…
From the same input (stored in input.mat in the attachment), I calculate the matrix M in 2 different ways and then calculate its evals and evecs.
Case 1:
clear;load('input.mat');D = d.^(-1/2);D = diag(D);M = D*L*D;[V, v] = eig(M);
Case 2:
clear;load('input.mat');d = sqrt(d);D = d * d';M = L./D;[V, v] = eig(M);
Clearly, the 2nd way is more efficient, BUT the resulting matrix M is the same for the 2 cases. So the eig() function should probably have the same running time in the both cases. However, for the first case the run time of eig() is about 12.5 s, and for the second case the run time of eig() is about 1.8 s (the numbers were taken from the profile results).
The input matrix L is a matrix with many zeros (but it's a full matrix). The input vector d is such that isequal(diag(L),d) is true.
I've uploaded the inputs because the above mysterious behaviour is apparently not present for a randomly generated input square matrix.
I guess, it might have something to do with memory efficiency or cache usage, but it would be interesting to know a more precise reason.
Best Answer