2015-10-12 160 views
0

我想用inv()函數得到逆矩陣。 Excel函數工作正常,但我無法從Stata的11和12的Stata版本Stata逆矩陣函數

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 
+0

這裏有什麼期望,Stata應該匹配Excel的數字? –

+0

我有一個很好的例子:givven數據的矩陣逆: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 – Nurlan

+0

而結果就像我在下面寫的 – Nurlan

回答

1

我相信問題是你的矩陣是病態的,即幾乎是單數。

如果你試圖計算馬塔(的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 | . . . . . . . . . . | 
    +---------------------------------------------------+ 

夫婦,與:

如果你使用這些功能用奇異矩陣,返回的將是一個缺失值的矩陣 。奇點的確定是由 相對於得到。見公差根據備註 in [M-5] lusolve()瞭解詳情。

來源:help mf_luinv

檢查條件數,我們看到它是非常高的,確認病態:

: C = cond(A) 

: C 
    7.47519e+17 

數值方法不盡相同,但對於這樣一個矩陣,你可以期待大的誤差。如上所述見help mf_lusolve##remarks3