MATLAB: Inverse of complex matrix

complex matrixMATLABmatrix inverse

I'm trying to invert a complex matrix using inv() function.
turns out A*inv(A)I and inv(A)*AI .
Of course I'm aware of precision errors, but here I got elements greater than 100 off the main diagonal.
Is there any reason for that?

Best Answer

Yes if you have badly conditioned (or badly scaled), or practically singular matrix. Usualy you get a warning message when computing the inverse.
This happens with real matrix as well, such as
>> M=magic(6)
M =
35 1 6 26 19 24
3 32 7 21 23 25
31 9 2 22 27 20
8 28 33 17 10 15
30 5 34 12 14 16
4 36 29 13 18 11
>> iM=inv(M)
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 8.001607e-19.
iM =
1.0e+15 *
2.251799813685250 -0.000000000000000 -2.251799813685250 -2.251799813685250 -0.000000000000000 2.251799813685250
2.251799813685250 -0.000000000000000 -2.251799813685250 -2.251799813685250 -0.000000000000000 2.251799813685250
-1.125899906842625 0.000000000000000 1.125899906842625 1.125899906842625 0.000000000000000 -1.125899906842625
-2.251799813685250 0.000000000000000 2.251799813685250 2.251799813685250 0.000000000000000 -2.251799813685250
-2.251799813685250 0.000000000000000 2.251799813685250 2.251799813685250 0.000000000000000 -2.251799813685250
1.125899906842624 0 -1.125899906842624 -1.125899906842624 0 1.125899906842624
>> M*iM
ans =
-8.000000000000000 0 8.000000000000000 8.000000000000000 -1.125000000000000 0
0 1.000000000000000 0 0 -0.962843041164940 0.500000000000000
8.000000000000000 -0.000000000000001 -8.000000000000000 -8.000000000000000 -1.773627835340241 8.000000000000000
8.000000000000000 0 -8.000000000000000 -8.000000000000000 0.249352422290674 12.000000000000000
4.000000000000000 0.000000000000000 -4.000000000000000 -4.000000000000000 0.411509381125735 12.000000000000000
8.000000000000000 0 -8.000000000000000 -8.000000000000000 -0.399275413049567 20.000000000000000
>> iM*M
ans =
0 16 9 -2 4 -2
0 20 9 -2 4 0
4 -2 -2 -1 2 1
2 8 6 0 8 6
0 -4 -9 -2 0 0
0 0 0 0 0 0
>> cond(M)
ans =
4.700154791029550e+16
>>