I'm trying some basic linear algebra function. I want to solve a singular matrix which is not easy to get inverse matrix.
for example, I have
A = [-1, 0, 0, 0, 1, 0, 0, 0; 0, -1, 0, 0, 0, 1, 0, 0]
since is non-inevitable, we should use SVD to get the inverse.
I try this code (skiped the steps to assign value to A)
Mat inverse= (A).inv(DECOMP_SVD);
cout << "A * inverse = " << inverse*A << endl;
cout << "inverse * A = " << A*inverse << endl;
and the outputs would be
A * inverse =
[0.5, 0, 0, 0, -0.5, 0, 0, 0;
0, 0.5, 0, 0, 0, -0.5, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0;
-0.5, 0, 0, 0, 0.5, 0, 0, 0;
0, -0.5, 0, 0, 0, 0.5, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0]
(bad)
inverse * A =
[1, 0;
0, 1]
(good)
so the left inverse not equal to the right inverse. However in the function I can just get the right one. How should I get the left one?