利用Numpy函数库构造4*4随机数组,然后将数组转化为矩阵,然后矩阵与其逆矩阵相乘,计算机处理的误差
from numpy import *
random.rand(4,4)
print(random.rand(4,4))
randMat = mat(random.rand(4,4))
print(randMat.I)
invRandMat = randMat.I
print(randMat*invRandMat)
myEye =randMat*invRandMat
print(myEye-eye(4))
运行结果
[[0.54780499 0.9731252 0.07999005 0.20705301]
[0.83245801 0.75284604 0.18425467 0.7834412 ]
[0.09396942 0.1107489 0.18763277 0.23205389]
[0.89786283 0.91400903 0.70443891 0.24994367]]
[[ 0.71761206 -0.90259973 1.90020797 -0.65588767]
[-1.33090238 1.66702845 -0.95849727 0.13763683]
[-0.48344954 -0.11453009 0.20771906 1.11689553]
[ 0.99169396 0.32033339 -1.06002074 0.14263029]]
[[ 1.00000000e+00 -1.66533454e-16 0.00000000e+00 -8.32667268e-17]
[ 0.00000000e+00 1.00000000e+00 -2.22044605e-16 -8.32667268e-17]
[-8.32667268e-17 -1.38777878e-16 1.00000000e+00 -8.67361738e-17]
[-5.55111512e-17 0.00000000e+00 -1.11022302e-16 1.00000000e+00]]
[[ 0.00000000e+00 -1.66533454e-16 0.00000000e+00 -8.32667268e-17]
[ 0.00000000e+00 0.00000000e+00 -2.22044605e-16 -8.32667268e-17]
[-8.32667268e-17 -1.38777878e-16 0.00000000e+00 -8.67361738e-17]
[-5.55111512e-17 0.00000000e+00 -1.11022302e-16 2.22044605e-16]]