Ask Your Question

Revision history [back]

Very different matrix inverse result in complex ring CC and in real ring RR while entry only contain real elements

I would use an dramatized example here but it was encountered during a project as well.

Suppose two matrix consisted of the same entry of only real elements. However, one was in the real domain RR, and one was in the complex domain CC. The inverse of the complex matrix and the real matrix different significantly.

Example:

test_S=matrix(RR,5)
for ix in range(0,5):
    for iy in range(0,5):
        test_S[ix,iy]=sin(ix+iy)*sin(iy+1);

and

test_S_CC=matrix(CC,5)
for ix in range(0,5):
    for iy in range(0,5):
        test_S_CC[ix,iy]=sin(ix+iy)*sin(iy+1);

which returned

test_S

[  0.000000000000000   0.765147401234293   0.128320060202457  -0.106799974237582   0.725716283876408]
[  0.708073418273571   0.826821810431806  0.0199148566748170   0.572750016904307   0.919535764538226]
[  0.765147401234293   0.128320060202457  -0.106799974237582   0.725716283876408   0.267938303940044]
[  0.118748392158235  -0.688158561598754  -0.135323401369264   0.211462346264655  -0.630000397639817]
[ -0.636827341031836  -0.871947375471875 -0.0394311173578842  -0.497209097294248  -0.948719639025321]

test_S_CC

[  0.000000000000000   0.765147401234293   0.128320060202457  -0.106799974237582   0.725716283876408]
[  0.708073418273571   0.826821810431806  0.0199148566748170   0.572750016904307   0.919535764538226]
[  0.765147401234293   0.128320060202457  -0.106799974237582   0.725716283876408   0.267938303940044]
[  0.118748392158235  -0.688158561598754  -0.135323401369264   0.211462346264655  -0.630000397639817]
[ -0.636827341031836  -0.871947375471875 -0.0394311173578842  -0.497209097294248  -0.948719639025321]

However, their inverse

(test_S)^-1

[ 2.87043424444896e15 -9.36229301025494e15  1.13569572695379e16 -8.12065238284797e15  1.72141024999095e15]
[-1.10320559226948e15  3.19497062929143e15  5.27553667803348e15 -7.22878751888619e15  8.54302211670640e15]
[ 1.94664421070014e16 -3.02112860544102e15    0.000000000000000  1.80143985094820e16    0.000000000000000]
[ 8.29739198582516e14  9.39732200089164e15 -1.02939420054183e16  1.02939420054183e16    0.000000000000000]
[-2.15677123538261e15 -1.45141888820365e15 -7.07708512872506e15  5.95118522188244e15 -9.00719925474099e15]

(test_S_CC)^-1

[-1.00798918109020e16  1.87532050063097e15  1.07471168476593e16 -2.09935440833922e16  1.10831351979113e16]
[ 2.64758058163658e15  7.44366790239271e15 -8.04492396917722e15  9.82621377301499e15  4.42753908914828e14]
[ 2.35701470124050e16 -4.71646526274252e15  1.02939420054183e16  1.08658276723860e16  9.15017067148291e15]
[ 1.53627372015977e16 -1.32579194813951e15 -1.02939420054183e16  2.51629693465780e16 -9.15017067148291e15]
[-4.69821640166124e15 -7.20926442861200e15  5.14697100270914e15 -8.57828500451523e15 -3.43131400180609e15]

where

(test_S)^(-1)-test_S_CC^(-1)

[ 1.29503260553510e16 -1.12376135108859e16  6.09840421878568e14  1.28728917005442e16 -9.36172494792037e15]
[-3.75078617390606e15 -4.24869727310128e15  1.33204606472107e16 -1.70550012919012e16  8.10026820779157e15]
[-4.10370490540364e15  1.69533665730150e15 -1.02939420054183e16  7.14857083709603e15 -9.15017067148291e15]
[-1.45329980030152e16  1.07231139490312e16    0.000000000000000 -1.48690273411597e16  9.15017067148291e15]
[ 2.54144516627863e15  5.75784554040835e15 -1.22240561314342e16  1.45294702263977e16 -5.57588525293490e15]

Is this a bug? How to fix the issue?