# A case for matrix multiplication (a.b).c unequal to a.(b.c) in mathematica 12.0.0.0, why?

The motivation of my calculation is to get the inverse for the following matrix

c={{806187941679782.0, 218884444558405.0, -44574352.7996484,
263790009.291711, -7043899062155.16 , 101619269971218.0},
{218884444558405.0, 59429013469996.9, -12139526.3237759,
71717183.1728141, -1913730353321.76, 27580785304831.0},
{-44574352.7996484, -12139526.3237759,
5.06604715779434, -20.0242999918957,
455028.9823731, -5189609.42411989},
{263790009.291711, 71717183.1728141, -20.0242999918957,
100.006624596537, -2482688.13923785, 31962666.0977317},
{-7043899062155.16, -1913730353321.76,
455028.9823731, -2482688.13923785 ,
63930635211.802, -869762434934.025},
{101619269971218.0, 27580785304831.0, -5189609.42411989,
31962666.0977317, -869762434934.025, 12957503435300.3}}


A direct "b=Inverse[c]" gives the following warning

Inverse::luc: Result for Inverse of badly conditioned matrix (<<1>>) may contain significant numerical errors.


Not surprisingly, the diverge of "b.c" from the identity matrix is large. Then I try to use the matrix

a=Inverse[Inverse[c].c]


as a correction. The new Inverse is "a.b". When I test the new inverse, Mathematica gives the following results which are obviously different.

Why do this happen? Besides, is there any better way to perform the matrix inversion in this case?

• there is no m matrix. I assume you meant c instead of m everywhere. But let me make sure I understand. You are using outputs that Mathematica says may contain significant numerical errors and then wondering why the result of (a.b).c is different from a.(b.c.) ? is it possible they are different result due to these numerical errors? Nov 3, 2021 at 5:00
• is there any better way to perform the matrix inversion why are you trying to do matrix inverse in first place. Normally this is not needed, unless for academic exercise. Are you try to solve a system of equations? Nov 3, 2021 at 5:05
• Thanks for you reminding. I meant "c" when I use "m". The only operation involves the "significant numerical errors" is "b=Inverse[c]", while the operation "(a.b).c" and "a.(b.c)" gives no warning. It may be possible that the numerical errors in "b" cause such difference. But I hope to make things clear. @Nasser Nov 3, 2021 at 5:22
• You can check the condition number of the matrix before doing inverse. Your c matrix has very large condition number, which is not good for inverse. LUDecomposition[c][] gives 2.90361*10^21. This is practically a singular matrix. Condition number should be small. less than 100 at most. but this really depends. I do not think there is a fixed number to look for, but the smaller it is, the better for inversion. Nov 3, 2021 at 5:32
• Instead of the Inverse for badly conditioned matrices, the "PseudoInverse", also called "Moore[Dash]Penrose inverse" is used. Look it up in the help. Nov 3, 2021 at 8:19