Path: news.mathworks.com!not-for-mail
From: "John D'Errico" <woodchips@rochester.rr.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Inverse of a Matrix
Date: Tue, 2 Oct 2007 09:40:50 +0000 (UTC)
Organization: John D'Errico (1-3LEW5R)
Lines: 83
Message-ID: <fdt3n2$kej$1@fred.mathworks.com>
References: <fdsglc$6b7$1@fred.mathworks.com>
Reply-To: "John D'Errico" <woodchips@rochester.rr.com>
NNTP-Posting-Host: webapp-06-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1191318050 20947 172.30.248.36 (2 Oct 2007 09:40:50 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 2 Oct 2007 09:40:50 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 869215
Xref: news.mathworks.com comp.soft-sys.matlab:430949



"Ravi " <vioravis.nospam@gmail.com> wrote in message <fdsglc$6b7
$1@fred.mathworks.com>...
> Are there any methods available for finding approximate
> inverse for nearly singular matrices using MATLAB? Is there
> a way to avoid this?

As Duane points out, why do you want the inverse at all?

If you are using it to solve a system of equations, then
its a very poor choice.

A pseudo-inverse, as provided by pinv will be a good
choice however. It uses the svd to survive the singularity,
and your result will be as stable as is numerically possible.
For example:

A = ones(2);
A(1,1) = 1+eps;


inv(A)
Warning: Matrix is close to singular or badly scaled.
         Results may be inaccurate. RCOND = 5.551115e-17.
ans =
   4.5036e+15  -4.5036e+15
  -4.5036e+15   4.5036e+15


pinv(A)
ans =
         0.25         0.25
         0.25         0.25


A*pinv(A)
ans =
          0.5          0.5
          0.5          0.5


A*inv(A)
Warning: Matrix is close to singular or badly scaled.
         Results may be inaccurate. RCOND = 5.551115e-17.
ans =
     1     0
     0     1


However, perturb A only by a tiny bit and see how
much the inverse changes. 

B = A;
B(2,2) = 1-eps;

inv(B)
Warning: Matrix is singular to working precision.
ans =
   Inf   Inf
   Inf   Inf


Or instead, try this:


B*inv(A)
Warning: Matrix is close to singular or badly scaled.
         Results may be inaccurate. RCOND = 5.551115e-17.
ans =
            1            0
            1            0
 

Whereas pinv(B) is still the same stable result.


pinv(B)
ans =
         0.25         0.25
         0.25         0.25

HTH,
John