Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Inverse of a large sparse matrix

Subject: Inverse of a large sparse matrix

From: Elia

Date: 24 Feb, 2007 14:22:18

Message: 1 of 7

Hi All,

I need find the inverse of a very large sparse martix.
The size of the matrix is near 16000^2.
The problem ofcourse is that Matlab yields : "Out of memory" ,when I
use B=inv(A);
I know that there are some clever algorithms to exploit the fact that
the matrix is sparse and most of its values are zeros and to find the
inverse in some other way without exceeding the limit of memory but I
dont know how.
I tired to use the operator '\' but it didnt work either.

If somebody knows how to do it , please help .

Thanks,
Elia.

Subject: Inverse of a large sparse matrix

From: Nasser Abbasi

Date: 24 Feb, 2007 13:19:07

Message: 2 of 7


"Elia" <aa2004a@gmail.com> wrote in message
news:ef4ebb5.-1@webcrossing.raydaftYaTP...
> Hi All,
>
> I need find the inverse of a very large sparse martix.
> The size of the matrix is near 16000^2.
> The problem ofcourse is that Matlab yields : "Out of memory" ,when I
> use B=inv(A);
> I know that there are some clever algorithms to exploit the fact that
> the matrix is sparse and most of its values are zeros and to find the
> inverse in some other way without exceeding the limit of memory but I
> dont know how.
> I tired to use the operator '\' but it didnt work either.
>
> If somebody knows how to do it , please help .
>
> Thanks,
> Elia.

is your A allready sparse? i.e. does doing

C=sparse(A)
B=inv(C)

help?

Why are trying to find the inverse of A anyway directly? it is almost always
not a good approach.
if you are trying to solve Ax=b, then use '\' (also make A explicitly
sparse using the sparse command)

hth

Nasser

Subject: Inverse of a large sparse matrix

From: ellieandrogerxyzzy@mindspring.com.invalid (Roger Stafford)

Date: 24 Feb, 2007 22:28:02

Message: 3 of 7

In article <ef4ebb5.-1@webcrossing.raydaftYaTP>, Elia <aa2004a@gmail.com> wrote:

> Hi All,
>
> I need find the inverse of a very large sparse martix.
> The size of the matrix is near 16000^2.
> The problem ofcourse is that Matlab yields : "Out of memory" ,when I
> use B=inv(A);
> I know that there are some clever algorithms to exploit the fact that
> the matrix is sparse and most of its values are zeros and to find the
> inverse in some other way without exceeding the limit of memory but I
> dont know how.
> I tired to use the operator '\' but it didnt work either.
>
> If somebody knows how to do it , please help .
>
> Thanks,
> Elia.
------------------
  Do you actually need the inverse of A itself, or is it just an
intermediate quantity toward some other goal? If the latter is the case,
there is often a means of getting around finding an inverse. If the goal
is to solve a system of linear equations, then using the backslash
operator will better serve that purpose (though you did state that doing
this gave you and out-of-memory message too.) Perhaps you should indicate
to this group what you are trying to achieve.

  If you are trying to find the inverse for its own sake, you should be
aware that even if A is sparsely filled with non-zero values, it is very
doubtful that its inverse will also be similarly sparse. Your
out-of-memory messages may simply be indicating that your computer does
not have enough memory to store all the non-zero values of an inverse,
never mind whether it is in matlab's sparse format or not. (In fact, if
the non-zeros of a matrix are not actually sparse, then using the sparse
format could use up more memory than with the ordinary format.)

Roger Stafford

Subject: Inverse of a large sparse matrix

From: Tim Davis

Date: 26 Feb, 2007 08:30:44

Message: 4 of 7

Inverting a sparse matrix, or any matrix, is usually a bad idea. The
inverse of a sparse matrix is typically full. Using the inverse,
except in very special applications, it almost always a bad idea, in
terms of the errors you will get.

To get a quick look at the sparsity pattern of the inverse, do [p q r
s] = dmpmerm(A). The number of diagonal irreducible blocks is given
by length(r)-1. If this is 1, then the inverse is complete full
(with the possible exception of "chance" numerical cancellation).

The size of each diagonal block is given by diff(r). Each of these
blocks will be completely full, in the inverse of A. If any of them
is very large, you won't be able to compute the inverse.

What do you need the inverse for? If you need just a few entries
(say the jth column) then try

n = size (A,1);
I = speye (n) ;
xj = A\I(:,j) ;

then xj will be the jth column of inv(A).

My guess is that if you rethought your problem, you would realize
that you do not need the inverse at all.

Subject: Inverse of a large sparse matrix

From: Phil

Date: 14 Mar, 2007 05:41:47

Message: 5 of 7

Hi,

I really need to invert a very large matrix M, and I have the same
"out of memory" problem than Elia. M is a multi-diagonale matrix. I
am not looking just for one element of I=inv(M), but for I as a
whole.

I am seraching the invert of this matrix because I am running an
implicit numeric scheme for the equation of diffusion on a 2D
inhomogene space with a large number of nodes.

I have not find the solution to my problem yet. If someone can help
it will be really appreciate.

Subject: Inverse of a large sparse matrix

From: Nasser Abbasi

Date: 14 Mar, 2007 04:00:20

Message: 6 of 7


"Phil" <steer@clipper.ens.fr> wrote in message
news:ef4ebb5.3@webcrossing.raydaftYaTP...
> Hi,
>
> I really need to invert a very large matrix M, and I have the same
> "out of memory" problem than Elia. M is a multi-diagonale matrix. I
> am not looking just for one element of I=inv(M), but for I as a
> whole.
>
> I am seraching the invert of this matrix because I am running an
> implicit numeric scheme for the equation of diffusion on a 2D
> inhomogene space with a large number of nodes.
>
> I have not find the solution to my problem yet. If someone can help
> it will be really appreciate.

do you want to solve for Ax=b, right? why exactly you want to find A inverse
explicitly?

There are many algorithms to solve Ax=b (based on Gaussian Elimination)
without finding inv(A).

For diagonal matrices, there are specific algorithms also that take
advatnages of this (Thomas algorithm for example for tridiagonal), and
similar ones for penta-diagonal. But not sure for multi-diagonal. I am sure
these can be extended.

You could also find inv(A) from Gauss-Jordan method. [A | I] ---->
G.J. ----> [ I | inv(A) ]

I am just curious, why you say that you HAVE to find inv(A) directly?

Nasser

Subject: Inverse of a large sparse matrix

From: Tim Davis

Date: 14 Mar, 2007 15:52:44

Message: 7 of 7

Phil wrote:
>
>
> Hi,
>
> I really need to invert a very large matrix M, and I have the same
> "out of memory" problem than Elia. M is a multi-diagonale matrix. I
> am not looking just for one element of I=inv(M), but for I as a
> whole.
>
> I am seraching the invert of this matrix because I am running an
> implicit numeric scheme for the equation of diffusion on a 2D
> inhomogene space with a large number of nodes.
>
> I have not find the solution to my problem yet. If someone can help
> it will be really appreciate.

What do you want do with the inverse of M? inv(M) is the best way to
compute it, if you must. It will be a dense matrix from what you
describe about M (see above on how to use dmperm to tell if inv(M)
will be completely dense or not). If M comes from a 2D mesh, then
most likely inv(M) will be completely dense.

However, if all you do with the inverse is to multiply it by
something else, then you are making a grave mistake. Never ever do
inv(M)*C, use M\C instead. For C*inv(M), use C/M instead. See "doc
inv" for more details.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us