MATLAB: When is eigs profitable in terms of time comparing to eig

eigenvalues eigsMATLAB

Hi,
I am busy with calculating eigenvalues of generalized symmetric matrices. So I am looking for (\lambda, x) such that Ax = \lambda B x. Furthermore B is considered to be positive definite.
I am wondering when for calculating the minimal eigenvalue (in this case the eigenvalues are real) it is profitable to use eigs instead of eig in terms of time spent on the calculation.
I only expect some rule of thumb.

Best Answer

There is no clear answer, since this depends on many factors: - Are your matrices dense or sparse, and if they are sparse, how sparse and with what sparsity structure? - Are the eigenvalues clustered closely together?
If we're assuming that all your matrices are dense and nicely conditioned, we can just try it out using random matrices (note that the performance here is also machine-dependent):
rng default;
A = randn(n);
A = A+A';
B = randn(n);
B = B*B';
tic;
[U, D] = eig(A, B);
toc
tic;
[U, D] = eigs(A, 1, 'smallestabs');
toc
For n = 1000, EIGS is faster:
Elapsed time is 0.181162 seconds.
Elapsed time is 0.039232 seconds.
For n = 200, they take comparable amounts of time:
Elapsed time is 0.016852 seconds.
Elapsed time is 0.011491 seconds.
For n = 100, EIG is faster:
Elapsed time is 0.004331 seconds.
Elapsed time is 0.036057 seconds.
Even for sparse matrices, I'd typically use EIG instead of EIGS for n<100.
Related Question