为什么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'.
In your particular case, you will see that:
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.
Your value is 0.07, which is quite close to 0, therefore your A matrix is rather poorly conditioned.
To learn a bit more what "poorly conditioned" means exactly, we can have a look at the 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.
In your case:
cond(A,2)
% ans = 7.080943875445246
所以你已经得到它了。您的矩阵条件相对较差,这意味着其求逆更容易受到精度误差的影响。如果您使用 mldivide
(即 \
运算符),可能会获得更好的结果。
关于matlab - 为什么 inv(matrix)*matrix 不是 Octave 中的精确单位矩阵?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67837413/