ksh0929 / efficient-java-matrix-library

Automatically exported from code.google.com/p/efficient-java-matrix-library
0 stars 0 forks source link

Matrix inverse is not correct when matrix is close to singular #20

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. crate a SimpleMatrix like the following 2x3 matrix. Name it x
    67.037029  -61.565225  1
    12.015528  -74.2136835  1
2. SimpleMatrix result = x.transpose().mult(x).invert();

What is the expected output? What do you see instead?

The returned result is far from what Matlab gives me.
And Matlab appears to be correct (even though Matlab says the matrix is close 
to singular).

Matlab source code:
x=[67.037029 -61.565225 1; 12.015528 -74.2136835 1];
result = (x' * x) \ [1 0 0 ; 0 1 0; 0 0 1]

Using Matlab to calculate it, it returns the following:

1.0e+015 *

    0.0000   -0.0002   -0.0154
   -0.0002    0.0009    0.0669
   -0.0154    0.0669    5.1470

Warning: Matrix is close to singular or badly scaled.
         Results may be inaccurate. RCOND = 1.323178e-020.

Original issue reported on code.google.com by GalaxyH on 16 Nov 2011 at 9:49

GoogleCodeExporter commented 8 years ago
I think this is less of a bug and more of an arbitrary design decision.  There 
is no standardized way for how to handle nearly singular matrices.  I could add 
logic to detect that condition, but that would slow the code down.

If you need the inverse of a poorly conditioned matrix I would suggest checking 
out the latest SVN code and using pinv() instead.  There has been a recent 
change to pinv().  THe pseudo inverse can now be called directly from using 
SimpleMatrix.pseudoInverse().

Original comment by peter.ab...@gmail.com on 16 Nov 2011 at 3:17

GoogleCodeExporter commented 8 years ago
Assuming that this issue is resolved.  Either e-mail me or leave a comment if 
you wish to discuss it further.

Original comment by peter.ab...@gmail.com on 24 Nov 2011 at 6:01

GoogleCodeExporter commented 8 years ago
Thanks a lot!

Original comment by GalaxyH on 25 Nov 2011 at 1:12