为什么 inv(matrix)*matrix 在 Octave 中不是精确的单位矩阵?

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

为什么inv(A)*A不是精确的单位矩阵? 所有对角线元素都是正确的,但其余部分不正确。 了解到这是残差,那怎么处理呢?

代码:

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

输出:

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

那么,这个值是什么意思?可以在相关函数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 函数:

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(即 \ 运算符),您 可能会 获得更好的结果。