Link to home
Start Free TrialLog in
Avatar of tadsyoung
tadsyoung

asked on

Calculate sparse inverse matrix in MATLAB

I have a large square n x n matrix where n = 1,000,000. I need to calculate the inverse of this matrix. This would take a long time to do directly.  However, the inverse matrix is very sparse.  I know which elements of the inverse matrix are non-zero, and each row (and column) only has 100 non-zero entries.
So I thought I could directly calculate each of these 100,000,000 elements of the inverse matrix. Therefore I need MATLAB code to calculate individual elements of an inverse matrix in a much faster way than simply taking the inverse and checking the individual elements.

That is, given a matrix M, find element (i,j) of inv(M) quickly and directly using MATLAB. The answer must be much faster to calculate than simply taking the inverse and checking the appropriate elements.
Avatar of tadsyoung
tadsyoung

ASKER

C or C++ code I could compile into a MEX file would also be okay.
Avatar of d-glitch
What is the context of this question?
What is the data and where are you getting it?
What sort of job/project/assignment is this?

Isn't this functionality built into MATLAB already?

     http://www.mathworks.com/access/helpdesk/help/techdoc/math/f6-19352.html#f6-41044
This is an attempt to make a research project work faster. The input matrix is a covariance matrix, and I am trying to obtain the inverse covariance matrix. Matlab can, of course, take the inverse of a matrix.  But because my matrix is so large, and has special properties (i.e. the output matrix is sparse) I thought there must surely be a better way to do it.

This is how the input matrix (cov) is created, and how it is used (out):




for j=1:size(x,1);
            covpart(:,:,j)=gaussians(j)*(distance_vector(:,j)*distance_vector(:,j)');      
end
cov=sum(covpart,3); 

out=exp(-.5*(distance_vector'/cov)*distance_vector);

Open in new window

"distance_vector" in line 6 is a different variable than any of the distance vectors in line 2.  Sorry for the confusion there.
Can you transform your matrix into a Block diagonal matrix?
   http://en.wikipedia.org/wiki/Block_matrix#Block_diagonal_matrices

or a band matrix?
   http://en.wikipedia.org/wiki/Band_matrix#Band_storage

Free C/C++ Sources for Numerical Computation
  http://cliodhna.cop.uop.edu/~hetrick/c-sources.html

A matlab paper on sparse matrix:
   http://www.mathworks.com/access/helpdesk/help/pdf_doc/otherdocs/simax.pdf
ASKER CERTIFIED SOLUTION
Avatar of QCD
QCD
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks, this was really helpful.