簡體   English   中英

為什么 inv(matrix)*matrix 不是 Octave 中的精確單位矩陣?

[英]Why inv(matrix)*matrix is not exact identity matrix in Octave?

為什么inv(A)*A不是精確的單位矩陣? 所有對角線元素都是正確的,但 rest 不正確。 我了解到這是殘差,那么如何處理呢?

代碼:

A = [1,2,0;0,5,6;7,0,9]
A_inv = inv(A)
A_invA = inv(A)*A

OUTPUT:

代碼

inv文檔的探索將引導您沿着以下路徑前進,它很好地回答了您的問題(強調我的問題):

octave:1> help inv
'inv' is a built-in function from the file libinterp/corefcn/inv.cc

 -- X = inv (A)
 -- [X, RCOND] = inv (A)
 -- [...] = inverse (...)
     Compute the inverse of the square matrix A.

     Return an estimate of the reciprocal condition number if requested,
     otherwise warn of an ill-conditioned matrix if the reciprocal
     condition number is small.

     In general it is best to avoid calculating the inverse of a matrix
     directly.  For example, it is both faster and more accurate to
     solve systems of equations (A*x = b) with 'Y = A \ b', rather than
     'Y = inv (A) * b'.

在您的特定情況下,您將看到:

A = [1,2,0;0,5,6;7,0,9];
[X, RCOND] = inv(A);
RCOND
% RCOND = 0.070492

那么,這個值是什么意思呢? 你可以在相關的 function rcond中找到答案,它直接計算這個值:

octave:2> help rcond
'rcond' is a built-in function from the file libinterp/corefcn/rcond.cc

 -- C = rcond (A)
     Compute the 1-norm estimate of the reciprocal condition number as
     returned by LAPACK.

     If the matrix is well-conditioned then C will be near 1 and if the
     matrix is poorly conditioned it will be close to 0.

     [...]

     See also: cond, condest.

您的值是 0.07,非常接近 0,因此您的 A 矩陣的條件很差。

要了解更多“條件差”的確切含義,我們可以查看cond function:

octave:26> help cond
'cond' is a function from the file /opt/octave-6.2.0/share/octave/6.2.0/m/linear-algebra/cond.m

 -- cond (A)
 -- cond (A, P)
     Compute the P-norm condition number of a matrix with respect to
     inversion.

     'cond (A)' is defined as 'norm (A, P) * norm (inv (A), P)'.

     [...]

     The condition number of a matrix quantifies the sensitivity of the
     matrix inversion operation when small changes are made to matrix
     elements.  Ideally the condition number will be close to 1.  When
     the number is large this indicates small changes (such as underflow
     or round-off error) will produce large changes in the resulting
     output.  In such cases the solution results from numerical
     computing are not likely to be accurate.

在你的情況下:

cond(A,2)
% ans = 7.080943875445246

所以你有它。 您的矩陣條件相對較差,這意味着它的求逆更容易受到精度誤差的影響。 如果您改用mldivide (即\運算符),您可能會得到更好的結果。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM