MATLAB: Eig algorithm and alternatives - matlab

I am simulating a physical system, where I need to calculate the eigenvalues and vectors of a very large (~10000x10000) matrix.
So far I have used the in-built Eig algorithm in MATLAB but it is very slow for large matrices. Is there other algorithms in MATLAB that would do a better job or can I somehow improve the performance of Eig? Specifically it turns out that I only need the first ~100 eigenvectors of the matrix starting from the smallest numerical eigenvalue. Is there a way to get the algorithm to calculate only the first N eigenvectors and eigenvalues to save computation time? Of course this would only work if the eigenvectors come out sorted but they seem to do so, because of the symmetry of the Matrix I am using.

Your matrix has mostly zeros, so you should make it a sparse matrix. You'll then be able to use EIGS to calculate a smaller number of eigenvalues and eigenvectors.
http://www.mathworks.com/help/matlab/ref/eigs.html

Related

scipy eigs finds complex eigenvectors, although they should be real

I have a 1047x1047 sparse matrix and am interested in its eigenvectors and eigenvalues. From the mathematical derivation I know that these must be real. scipy eigs finds complex ones though. Unfortunately this destroys everything. There is no possibility to create a minimal example, because for small matrices eigs also calculates real eigenvectors, i.e. complex eigenvectors with imaginary part zero.
Desperate thanks!

MATLAB: Get small eigenvalues from `eigs` in sorted order

For example, eigs(A,k,'sm') returns the k smallest magnitude eigenvalues. However, eigs does not take care of the sign. Edit: eigs(A,k,'sr')takes care of it.
Say A is 500 by 500 sparse matrix. Without getting all eigenvalues like in eig, how to get the smallest 3 eigenvalues (not magnitude) and the corresponding eigenvectors for eigs in a sorted way efficiently?
This can be done easily by getting all eigenvalues in eig by sorting but I cannot use eig for some reasons as it takes a long time and huge memory to convert to full matrix and compute all eigenvalues.
Edit: This can also be done by eigs(A,k,'sr') and do the sorting myself. But is there a faster method or option in eigs to do so?
It should not do that unless there is a syntax error or your matrix has all the eigenvalues with positive real part. This gives the correct negative signed smallest real part (I guess that's what you mean by small) eigenvalues on R2016a. Note that smallest eigs are complex conjugates and one pair is given by only its negative imaginary part.
A = sprand(100,100,0.5);
[V,D] = eigs(A,3,'sr')

Calculating large number of generalized eigenvalues with Matlab on GPU

I have a lot of small matrices already stored on GPU card and now I want to calculate their generalized eigenvalues with another matrix.
Current code:
cov=gpuArray(cov) %7x7 matrix;
p=1:numel(ix1); %numel(ix1)... number of stored matrices
p=gpuArray(p);
%covs... 7x7xn matrix already on GPU, n is large (>100000)
g = arrayfun(#(x) eig(covs(:,:,x)/cov), p);
If I tried to run code I get error that function eig is unsupported, but I read that eig is supported on GPU.
So my question is what I did wrong (my first attempt with arrayfun) and if there is better way to calculate generalized eigenvalues.

Fast Computation of Eigenvectors of a Sparse Matrix

I am working on a project that involves the computation of the eigenvectors of a very large sparse matrix.
To be more specific I have a Matrix that is the laplacian of a big graph and I am interested in finding the eigenvector associated to the second smallest eigenvalue.
Of course Matlab takes ages to compute the eigenvectors, even because it computes all of them.
Any suggestions?
Thank you very much
Andrea
Have you tried this usage of eigs:
[v,c]=eigs(A,2,'sm');
for example:
A = delsq(numgrid('C',256));
[v,c]=eigs(A,2,'sm');
generates a ~50K x 50K sparse matrix and find its 2 smallerst eigenvalues and eigenvectors in about 1 second in my old laptop...

Octave/Matlab: PCA on sparse matrix: how to get only the most important eigenvectors?

I am using Octave and have a huge sparse matrix that I have to get the eigenvalues of. However, if I just use a function to get all eigenvalues and eigenvectors, the result will take up way too much space, since the input matrix is sparse for a reason.
How can I get only a limited number of the most important eigenvectors?
Use eigs instead of eig:
D = eigs(A,k);
This returns the k largest eigenvalues of the matrix A. According to this page, Octave does support eigs for sparse matrices. eigs uses different techniques than eig, is slower overall, and shouldn't generally be used except in the cases such as the one you describe.
Be sure to check out the options for the sigma argument in case you want the largest eigenvalues with respect to their real parts only, for example.
The Matlab documentation for eigs is here.