Stata逆矩阵函数

时间:2015-10-12 05:17:11

标签: stata matrix-inverse

我试图通过inv()函数获得逆矩阵。 Excel功能工作正常,但我无法从Stata 11和Stata 12版本获得它

matrix A = (0,0,553959,18071,0,0,86985,0,0,0\0,0,13752,1986661,0,0,14178,0,0,0\245764,55172,0,0,0,0,210238,15835,0,174155\135950,1217897,0,0,211554,0,348453,197592,424893,704246\0,0,40442,171113,0,0,0,0,0,0\277015,720994,0,0,0,0,0,0,0,0\0,0,0,0,0,989861,121720,67779,0,58624\286,20529,34840,90896,0,8147,157021,265924,51955,4187\0,0,0,0,0,0,299389,86656,0,90804\0,0,58171,973844,0,0,0,0,0,0)
matrix list A
matrix D = inv(A)*A
matrix list D

我明白了:

    D[10,10]
             c1          c2          c3          c4          c5          c6          c7          c8          c9         c10
 c1   .99815163   -.0007439          24         256  -4.441e-18   .02180544   .63042827   .71306993   .13905754   .72740125
 c2   .00071017   1.0002858         -64        -640   1.978e-17  -.00837793   1.0656752  -.27397047  -.05342766  -.27947675
 c3   2.008e-20   8.082e-21    2.143632   20.313752           0  -2.369e-19   .08155506  -7.747e-18  -1.511e-18  -2.800e-19
 c4   7.748e-22   3.118e-22   .04412596   1.7837869           0  -9.141e-21   .00314672  -2.989e-19  -5.829e-20  -1.080e-20
 c5  -.03648975  -.01468572         512        2048           1     .430473   13.357737   14.077098   2.7452099   14.360021
 c6     .000033   .00001328      -1.125         -12           0    .9996107  -.09016952  -.01273068  -.00248264  -.01298654
 c7  -1.280e-19  -5.153e-20   -7.292322   -129.5298           0   1.511e-18   .47996753   4.940e-17   9.633e-18   1.785e-18
 c8  -.00276051    -.001111          32         512           0   .03256598   3.1088352   2.0649553   .20767957   1.0863588
 c9   .01364134   .00549012           0       -1024           0   -.1609282  -9.7734934  -5.2625881  -.02627036  -5.3683558
c10   .00263441   .00106025           0        -128           0  -.03107834  -1.6240499  -1.0163072   -.1981926  -.03673303

但我认为应该是:

1   0   0   0   0   0   0   0   0   0
0   1   0   0   0   0   0   0   0   0
14  -8  1   -9,42932E-17    -64 1,00614E-16 -1,73472E-18    0   1,33227E-15 32
0   -32 -5,55112E-17    1   0   1,11022E-16 0   0   0   -128
0,021597505 -0,210228064    0   0   0,788571331 4,27485E-20 2,13743E-20 0   5,47181E-18 0,788571331
0   0   0   0   0   1   0   0   0   0
0   0   0   0   -16 -8,67362E-19    1   0   0   0
3,5 -1,75   6,93889E-18 -2,7765E-19 -128    1,38778E-17 0   1   2,22045E-16 35
0   0   0   0   0   0   0   0   1   0
-0,007446191    -0,112499947    0   0   1,604924249 8,70031E-20 4,35016E-20 0   1,11364E-17 1,604924249

1 个答案:

答案 0 :(得分:1)

我认为问题是你的矩阵病态,即几乎是单数。

如果您尝试在 Mata (Stata的矩阵编程语言)中计算逆,结果为:

: Ainv = luinv(A)

: Ainv
[symmetric]
         1    2    3    4    5    6    7    8    9   10
     +---------------------------------------------------+
   1 |   .                                               |
   2 |   .    .                                          |
   3 |   .    .    .                                     |
   4 |   .    .    .    .                                |
   5 |   .    .    .    .    .                           |
   6 |   .    .    .    .    .    .                      |
   7 |   .    .    .    .    .    .    .                 |
   8 |   .    .    .    .    .    .    .    .            |
   9 |   .    .    .    .    .    .    .    .    .       |
  10 |   .    .    .    .    .    .    .    .    .    .  |
     +---------------------------------------------------+

结合以下:

  

如果将这些函数与奇异矩阵一起使用,则返回将为a   缺失值矩阵。确定奇点   相对于 tol 。请参阅 [M-5]中备注下的容差       lusolve()了解详情。

来源:help mf_luinv

检查条件编号,我们发现它非常高,确认了病情:

: C = cond(A)

: C
  7.47519e+17

数值方法各不相同,但对于像这样的矩阵,您会发现很大的不准确性。如上所示,请参阅help mf_lusolve##remarks3