Reputation: 57
I'm multiplying a matrix by it's inverse and not getting an identify matrix in return. My suspicion is there's an issue with the floating point rounding (or lack thereof if the original matrix entries are just ints?) All help is appreciated.
C = np.array([[5,5,5],[4,5,6],[7,8,9]])
print("Original matrix")
print(C)
print("Inverse matrix")
D = np.linalg.inv(C)
print(D)
print("Identity matrix")
print((C.dot(D)))
Original matrix
[[5 5 5]
[4 5 6]
[7 8 9]]
Inverse matrix
[[-6.75539944e+14 -1.12589991e+15 1.12589991e+15]
[ 1.35107989e+15 2.25179981e+15 -2.25179981e+15]
[-6.75539944e+14 -1.12589991e+15 1.12589991e+15]]
Identity matrix
[[ 0.5 -2. 1.75]
[ 0. 0. 0.5 ]
[ 0.5 0. 2.75]]
Upvotes: 1
Views: 1582
Reputation: 21
One of the matrix properties say that a matrix only has a inverse form if the determinate of it is different from zero. Your matrix C has zero as determinant, so it does not have a inverse. Numpy make calculation because it does not get zero, but an approximation that in practice is zero.
>>> np.linealg.det(C)
4.440892098500603e-15
in this case, the value of the determinant can be considered as zero.
Upvotes: 2