An error of matrix inversion using NumPy
Dayong Wang
wangday at gmail.com
Wed Apr 4 09:40:30 EDT 2007
Here below is the matrix KK I used:
[[ 1939.33617572 -146.94170404 0. 0. 0.
0. 0. 0. 0.
-1172.61032101
0. 0. -193.69962687 -426.08452381 0.
0. 0. 0. 1792.39447168]
[ -146.94170404 5175.33392519 -442.430839 0. 0.
0. 0. 0. 0. 0.
-3409.58801135 0. 0. 0.
-767.46969697
-408.90367384 0. 0. 4585.96138215]
[ 0. -442.430839 4373.33685159 0. 0.
0. 0. 0. 0. 0.
0. -2354.70959362 0. 0. 0.
0. -855.36922061 -720.82719836 3930.90601259]
[ 0. 0. 0. 17064.73017917
-949.49987581 0. 0. 0. 0.
0. 0. 0. -16115.23030336 0.
0. 0. 0. 0.
16115.23030336]
[ 0. 0. 0. -949.49987581
11005.53604312 -1358.01000599 0. 0. 0.
0. 0. 0. 0.
-8698.02616132
0. 0. 0. 0.
8698.02616132]
[ 0. 0. 0. 0.
-1358.01000599
18322.57142994 -1495.29428718 0. 0. 0.
0. 0. 0. 0.
-15469.26713677
0. 0. 0. 15469.26713677]
[ 0. 0. 0. 0. 0.
-1495.29428718 12497.65812936 -1858.81899672 0. 0.
0. 0. 0. 0. 0.
-9143.54484546 0. 0. 9143.54484546]
[ 0. 0. 0. 0. 0.
0. -1858.81899672 20170.17739075 -1249.5298217 0.
0. 0. 0. 0. 0.
0. -17061.82857234 0. 17061.82857234]
[ 0. 0. 0. 0. 0.
0. 0. -1249.5298217 9476.04289846 0.
0. 0. 0. 0. 0.
0. 0. -8226.51307677 8226.51307677]
[ -1172.61032101 0. 0. 0. 0.
0. 0. 0. 0. 1500.8055591
-328.1952381 0. 0. 0. 0.
0. 0. 0. -1172.61032101]
[ 0. -3409.58801135 0. 0. 0.
0. 0. 0. 0. -328.1952381
4112.15248021 -374.36923077 0. 0. 0.
0. 0. 0. -3409.58801135]
[ 0. 0. -2354.70959362 0. 0.
0. 0. 0. 0. 0.
-374.36923077 2729.07882439 0. 0. 0.
0. 0. 0. -2354.70959362]
[ -193.69962687 0. 0. -16115.23030336 0.
0. 0. 0. 0. 0.
0. 0. 17726.91399397 -1417.98406375 0.
0. 0. 0. -16308.92993023]
[ -426.08452381 0. 0. 0.
-8698.02616132
0. 0. 0. 0. 0.
0. 0. -1417.98406375 12320.46305747
-1778.36830859 0. 0. 0.
-9124.11068513]
[ 0. -767.46969697 0. 0. 0.
-15469.26713677 0. 0. 0. 0.
0. 0. 0. -1778.36830859
19552.18019195 -1537.07504962 0. 0.
-16236.73683374]
[ 0. -408.90367384 0. 0. 0.
0. -9143.54484546 0. 0. 0.
0. 0. 0. 0.
-1537.07504962
12983.70625768 -1894.18268877 0. -9552.44851929]
[ 0. 0. -855.36922061 0. 0.
0. 0. -17061.82857234 0. 0.
0. 0. 0. 0. 0.
-1894.18268877 21039.17951514 -1227.79903343 -17917.19779295]
[ 0. 0. -720.82719836 0. 0.
0. 0. 0. -8226.51307677 0.
0. 0. 0. 0. 0.
0. -1227.79903343 10175.13930856 -8947.34027513]
[ 1792.39447168 4585.96138215 3930.90601259 16115.23030336
8698.02616132 15469.26713677 9143.54484546 17061.82857234
8226.51307677 -1172.61032101 -3409.58801135 -2354.70959362
-16308.92993023 -9124.11068513 -16236.73683374 -9552.44851929
-17917.19779295 -8947.34027513 85023.67196244]]
On 4/4/07, BJörn Lindqvist <bjourne at gmail.com> wrote:
> On 4 Apr 2007 06:15:18 -0700, lancered <wangday at gmail.com> wrote:
> > During the calculation, I noticed an apparent error of
> > inverion of a 19x19 matrix. Denote this matrix as KK, U=KK^ -1, I
> > found the product of U and KK is not equivalent to unit matrix! This
> > apparently violate the definition of inversion. The inversion is
> > through the function linalg.inv().
>
> Could it have something to do with floating point accuracy?
>
> >>> r = matrix([[random.random() * 9999 for x in range(19)] for y in range(19)])
> >>> allclose(linalg.inv(r) * r, identity(19))
> True
>
> > So, can you tell me what goes wrong? Is this a bug in
> > Numpy.linalg? How to deal with this situation? If you need, I can
> > post the matrix I used below, but it is so long,so not at the moment.
>
> Please post it.
>
> --
> mvh Björn
>
More information about the Python-list
mailing list