Question

I am using opencv library in c++ for matrix inversion. I use the function invert with DECOMP_SVD flag. For matrices which are not singular, it computes using SVD method.

However it gives me an incorrect answer for singular matrices (determinant = 0) when I compare it to the output in Matlab for the same inversion.

The answer is off by a margin of 1e+4!

The methods I have used in matlab is pinv() and svd(). pinv() uses moore-Penrose method. Need help Thanks in advance!

Example :

original =

    0.2667    0.0667   -1.3333    2.2222
    0.0667    0.0667   -0.0000    0.8889
   -1.3333   -0.0000    8.8889   -8.8889
    2.2222    0.8889   -8.8889   20.7408


Inverse from matlab =

   1.0e+04 *

    9.8888   -0.0000    0.7417   -0.7417
   -0.0000    9.8888   -0.7417   -0.7417
    0.7417   -0.7417    0.1113    0.0000
   -0.7417   -0.7417    0.0000    0.1113

Was it helpful?

Solution

Your matrix is ill-conditioned (weak main diagonal). Try to increase the main diagonal elements, and, I think, the error should decrease.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top