from mpmath import *
mp.dps = 30; mp.pretty = True

A = matrix([[2338.2790843183961442, 2409376.8921373519115150, 64871.4630617255388643, 2177864.5559532525949180, -69.8183339219611554, -121.8898728187808302, 38.8666174262139705, 67.8996163479773429, ],
[2409376.8921373519115150, 2636961038.8102936744689941, 59475922.0576802715659142, 1995236353.5737774372100830, -64499.8278913961185026, -111620.5736668497411301, 35605.8535074569008430, 61646.5176898051868193, ],
[64871.4630617255388643, 59475922.0576802715659142, 2564844.0586994066834450, 86261573.6021927595138550, -2705.8448515296886399, -4832.4326534735191672, 1538.8881436949720865, 2751.5581630741667141, ],
[2177864.5559532525949180, 1995236353.5737774372100830, 86261573.6021927595138550, 2901196002.4222769737243652, -90996.0113994343118975, -162527.6426562610431574, 51756.6418445929593872, 92550.6966903222637484, ],
[-69.8183339219611554, -64499.8278913961185026, -2705.8448515296886399, -90996.0113994343118975, 3.7806732919259147, 6.7484796286274928, 0.0000000000000000, 0.0000000000000000, ],
[-121.8898728187808302, -111620.5736668497411301, -4832.4326534735191672, -162527.6426562610431574, 6.7484796286274928, 12.0609648498077959, 0.0000000000000000, 0.0000000000000000, ],
[38.8666174262139705, 35605.8535074569008430, 1538.8881436949720865, 51756.6418445929593872, 0.0000000000000000, 0.0000000000000000, 3.7806732919259147, 6.7484796286274928, ],
[67.8996163479773429, 61646.5176898051868193, 2751.5581630741667141, 92550.6966903222637484, 0.0000000000000000, 0.0000000000000000, 6.7484796286274928, 12.0609648498077959, ]]) 

B = powm(A, -1) 

print "\nDiagonal elements:" 

for i in range(0,B.rows): 
    print '%e' % B[i,i]

mp.dps = 16 

print "\nTest:" 

print (A*B)

print "\n"

A = matrix([[2338.2790843183961442, 2409376.8921373519115150, 64871.4630617255388643, 2177864.5559532525949180 ],
[2409376.8921373519115150, 2636961038.8102936744689941, 59475922.0576802715659142, 1995236353.5737774372100830 ],
[64871.4630617255388643, 59475922.0576802715659142, 2564844.0586994066834450, 86261573.6021927595138550 ],
[2177864.5559532525949180, 1995236353.5737774372100830, 86261573.6021927595138550, 2901196002.4222769737243652 ]])

print A 

B = powm(A, -1) 

print "\nDiagonal elements:" 

for i in range(0,B.rows): 
    print '%e' % B[i,i]

mp.dps = 16 

print "\nTest:" 

print (A*B)



