1

I implement a algorithm which is related to sparse matrix inversion.

The code:

kapa_t=phi_t*F_x'*(inv(inv(R_t)+F_x*phi_t*F_x'))*F_x*phi_t;

I write down the code in matlab. It give me a warning Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.419037e-18.. But as per my algorithm matrix inversion is important part. So, I am trying to search some efficient way for matrix inversion.So I find out this link how to compute inverse of a matrix accurately?
So I changed my code as suggest.

kapa_t=phi_t*F_x'*(inv(inv(R_t)+F_x*phi_t*F_x'))\F_x*phi_t;

After that I get an error Error using \ Matrix dimensions must agree.

Error in EKF_SLAM_known (line 105) kapa_t=phi_tF_x'(inv(inv(R_t)+F_xphi_tF_x'))\F_x*phi_t;

The algorithm I am using is enter image description here

Here line no: 8 of the algorithm is equivalent to code kapa_t=phi_tF_x'(inv(inv(R_t)+F_xphi_tF_x'))F_xphi_t;

What should I do with my code to get rid of this warning.

Saswati
  • 192
  • 8

1 Answers1

2
kapa_t=phi_t*F_x'*(inv(inv(R_t)+F_x*phi_t*F_x'))\F_x*phi_t;

should be

kapa_t=phi_t*F_x'*((inv(R_t)+F_x*phi_t*F_x')\F_x)*phi_t;

The A \ B operator is roughly equivalent to inv(A) * B when A is square, so you don't need the outer inv.

lightalchemist
  • 10,031
  • 4
  • 47
  • 55
  • Ok Thank you. Now it is work. But the same warning displayed again and again. **Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.419037e-18.**. Is there any way to stop the warning. because I have 40000 data so this warning will be iterated 40000 times. – Saswati Sep 19 '18 at 21:42
  • @Saswati The warning should not be ignored. It is saying that your matrix (or matrices) being inverted is/are ill-conditioned. Think of it as somewhat like the matrix equivalent of dividing by 0. You should use the `cond` function to check the condition number (Google this if not sure) of R_t and the expression inside the parentheses that be inverted. Then decide if you have a bug computing either of them or it is due to your data making them low rank. Else there are other hacks to improve their condition (e.g., adding small multiple of identity matrix to them) but that depends on your problem – lightalchemist Sep 20 '18 at 00:29
  • @Saswati The warning should not be taken as a nuisance. It is telling you that your results is likely invalid. If you can't figure out the problem, you might want to post a separate question with the relevant parts of your code, especially those that compute the matrices in that expression. – lightalchemist Sep 20 '18 at 00:54
  • Most of the matrices I used here are sparsed. I can create seperate link consist of matrices dimensions and the values inside it. – Saswati Sep 20 '18 at 13:29
  • I am using sparse matrix. What does it exactly mean by using rank deficient? Can you please help me to understand? – Saswati Sep 21 '18 at 21:41
  • @Saswati That just means the matrix is not full rank, so the matrix inverse is not well defined. The comment section is not meant for extended discussion so if your results does not look correct, post another question. – lightalchemist Sep 22 '18 at 02:21