# Finding inverse of an ill-conditioned matrix

## Question: Finding inverse of an ill-conditioned matrix

I am trying to implement a numerical method, which requires me to compute the inverse of a 6x6 matrix (A) at some point. This matrix consists of four 3x3 matrices (B1...4) `A = [[B1, B2], [B3, B4]]`. While the magnitude of the entries within a 3x3 matrix is roughly the same, the magnitude across the 3x3 matrices differs quite a lot. (Example of 6x6 matrix below)

Issue: When computing the inverse of this matrix, the resulting matrix deviates a lot from the expected result. I tried to confirm this by computing `I = A*A^-1`, but the result is far from the identity matrix. I assume this is the case due to the bad condition of the matrix since the differences between each 3x3 matrix are so large.

Does anyone know a method to compute the inverse of such a matrix?

My current idea would be to multiply each 3x3 matrix by a coefficient in order to lower the differences between each 3x3 matrix `A = [[B1*a, B2*b], [B3*c, B4*d]]`. After that, I would compute the inverse and then try to deduct the coefficients from the resulting matrix. However, I find it difficult to determine a way of performing the last step.

Example:

``[1.28872490245158e-06 1.4637613938654e-07 -1.70029707059287e-07 -18.6570630324193 -239.692934347905 -314.364362678385; 1.4637613938654e-07 1.6625715962304e-08 -1.9312338927429e-08 -2.1191092480495 -27.2248377456929 -35.7061787834127; -1.70029707059287e-07 -1.9312338927429e-08 2.24331051783591e-08 2.46154548263497 31.6242196715729 41.4760981140375; -18.6570630324193 -2.1191092480495 2.46154548263497 13813398787722.4 -52045116012728.7 59648566307319.4; -239.692934347905 -27.2248377456929 31.6242196715729 -52045116012728.7 456984106570523 1138610755446.41; -314.364362678385 -35.7061787834127 41.4760981140375 59648566307319.4 1138610755446.41 453138063298379] ``

## Answers 1: of Finding inverse of an ill-conditioned matrix

In your example 6x6 matrix, the first three columns are linearly dependent; the second python error column and third column are both just scalar multiples of the first column:

``>> a=<your example>; >> a(:,1:3)./a(:,[1 1 1]) ans =      1.000000000000000e+00     1.135821455052853e-01    -1.319363866841049e-01      1.000000000000000e+00     1.135821455052859e-01    -1.319363866841050e-01      1.000000000000000e+00     1.135821455052855e-01    -1.319363866841045e-01      1.000000000000000e+00     1.135821455052838e-01    -1.319363866841038e-01      1.000000000000000e+00     1.135821455052868e-01    -1.319363866841046e-01      1.000000000000000e+00     1.135821455052856e-01    -1.319363866841046e-01 ``

The inverse in this case doesn't really make sense; it's python error not just an issue with scaling among the different 3x3 submatrices.

Various possibilities:

• There's a bug in whatever generated the example and the correct matrix is reasonably conditioned (though perhaps badly scaled). Applying a simple diagonal scaling `sc = diag(1 ./ sqrt(diag(a)))` on both sides will usually fix the scaling if that's the only problem.
• The very slight difference in the last digits of the printing above is actually significant and not just rounding noise from the computation of `a`. I.e., they're actual signal and are what would really determine the result you want. Then you've just run out of precision in the normal representation. You'll have to do some sort of reformulation to make these visible.
• The column dependence is telling you something about the problem, and it's really a lower dimension than the 6x6. Taking into account the symmetry and looking at `a1 = a(3:6, 3:6)` (dropping the two dependent columns plus the corresponding rows), the result is badly scaled but `sc * a1 * sc` (with `sc` as above) is reasonable with a condition number of about `2e6`.