矩阵运算的结果准确性是否不合逻辑? [英] Is the resulting accuracy on matrix manipulation any ill-logical?
问题描述
octave:1> A = [1 2 3; 4 5 6; 7 8 9]
octave:2> B = pinv (A)
octave:3> I = eye (size (A))
ans =
Diagonal Matrix
1 0 0
0 1 0
0 0 1
octave:4> I2 = A * B
ans =
0.83333 0.33333 -0.16667
0.33333 0.33333 0.33333
-0.16667 0.33333 0.83333
octave:5> A2 = A * I2
ans =
1.00000 2.00000 3.00000
4.00000 5.00000 6.00000
7.00000 8.00000 9.00000
为什么最后一个步骤5会产生完美的准确性,而先前的步骤4却造成了无法原谅的准确性呢?
Why could the final Step 5 result in the perfect accuracy although the previous Step 4 in the unforgiving accuracy?
octave:6> format long
octave:7> I2
I2 =
0.833333333333332 0.333333333333332 -0.166666666666666
0.333333333333332 0.333333333333333 0.333333333333334
-0.166666666666668 0.333333333333333 0.833333333333334
octave:8> A2
A2 =
0.999999999999993 1.999999999999997 3.000000000000005
3.999999999999982 4.999999999999992 6.000000000000014
6.999999999999972 7.999999999999987 9.000000000000021
推荐答案
结果确实有错误,只是您的显示设置已将所有内容四舍五入到小数点后四位(format short
).如果我们更改显示格式(format long
),我们会看到错误:
The result does have errors, it's just that your display settings are such that everything is rounded to 4 decimal places (format short
). If we change the display format (format long
), we can see the errors:
format long
A * I2
% 0.999999999999990 1.999999999999998 3.000000000000007
% 3.999999999999978 4.999999999999993 6.000000000000017
% 6.999999999999965 7.999999999999987 9.000000000000027
或者,您可以使用num2str
显示小数点后的任意位数.
Alternately, you can use num2str
to show any arbitrary number of places after the decimal point.
% Show 32 places after the decimal point
num2str(A * I2, 32)
关于A * pinv(A) * A
为何近似等于A
的原因,这是
As for why A * pinv(A) * A
is approximately equal to A
, that is one of the defining properties of the Moore–Penrose pseudo-inverse computed by pinv
.
这篇关于矩阵运算的结果准确性是否不合逻辑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!