Registered Member
|
Hi,
I have an Eigen::MatrixXd m(9,9); And when I am doing this: m.inverse(); I am getting the same output. Is there any other way to invert such a large matrix? Thanks in advance. |
Moderator
|
As explained in the doc (http://eigen.tuxfamily.org/dox-devel/cl ... 030f79f9da), mat.inverse() returns the inverse of mat, keeping mat unchanged:
|
Registered Member
|
My problem is that when i calculate the inverse of my 9x9 matrix I get "nan" values.
I am having these values in my matrix: 1384.33 0 0 0 0 0 553.1 0 -1707.22 0 673.42 673.42 553.1 -601.406 229.515 0 241.537 0 0 673.42 673.42 553.1 -601.406 229.515 0 241.537 0 0 553.1 553.1 9288.69 771.387 4054.28 0 -672.069 0 0 -601.406 -601.406 771.387 2848.9 781.647 0 -777.88 0 0 229.515 229.515 4054.28 781.647 2986.75 0 -459.042 0 553.1 0 0 0 0 0 771.387 0 -672.069 0 241.537 241.537 -672.069 -777.88 -459.042 0 781.647 0 -1707.22 0 0 0 0 0 -672.069 0 4054.28 And when I printing the inverse I get: -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -nan -inf inf -nan -nan -nan -nan -nan -nan 0.000636602 0 0 0 0 0 -9.36032e-06 0 0.000513168 I am not getting what's going wrong. |
Moderator
|
Your matrix is singular, so not invertible. Confirmed by matlab:
If what you what is to solve for A x = b, or equivalently apply the inverse of A to tome matrices (A^-1 * B), then use a rank-revealing decomposition, e.g.:
|
Registered Member
|
Yeah...
this is what i want to do. x = bA^-1 where, x = 3x9 mat b = 3x9 mat A = 9x9 mat Is it possible to compute this with LU decomposition as I tried but it is crashing? Or can I get inverse of A using LU decomposition? |
Moderator
|
You have many options:
If you want to solve for the same matrix multiple times, build the respective factorization object as shown in my previous post. |
Registered Member
|
I get this error when I am doing this:
x = A.lu().solve(b) where, x = 3x9 mat b = 3x9 mat A = 9x9 mat DeformationDynamics: ./Eigen/src/LU/PartialPivLU.h:449: void Eigen::internal::solve_retval<Eigen::PartialPivLU<_MatrixType>, Rhs>::evalTo(Dest&) const [with Dest = Eigen::Matrix<double, 3, 9>; _MatrixType = Eigen::Matrix<double, 9, 9>; Rhs = Eigen::Matrix<double, 3, 9>]: Assertion `rhs().rows() == dec().matrixLU().rows()' failed. |
Moderator
|
x.transpose() = A.lu().solve(b.transpose());
|
Registered Member
|
Yeah...
I did that but I am still getting some "nan" values in my output matrix. |
Moderator
|
which solver did you tried? I shown the LU one for reference only, but is well known that a partial pivoting LU requires the matrix to be invertible, so not applicable in your case. This is also explain in our doc: http://eigen.tuxfamily.org/dox-devel/gr ... tions.html.
Have you tried the 3 others options I suggested? They are all working for me:
Output:
|
Registered Member
|
Thank you for the solution but I don't understand why these really large values (2.82792e-12) are coming and how can I avoid them?
And one more thing rather a stupid question but if the inverse of the matrix doesn't exist then how does the solution is reliable through these decomposition? |
Registered Member
|
|
Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], ourcraft