Numerical precision of matrix multiplication (inconsistent results with colon indexing)

1 次查看(过去 30 天)
Why do the two ways of matrix multiplication lead to different results?
rng(1);
A = randn(100,3);
B = A'*A;
C = A(:,:)'*A(:,:);
B-C
results in
ans =
1.0e-13 *
0 -0.0178 0.0133
-0.0178 -0.1421 -0.0133
0.0133 0.0311 0.1421
The difference is not huge, but still I don't understand why the results differ at all.

回答(1 个)

Jos (10584)
Jos (10584) 2014-2-27
编辑:Jos (10584) 2014-2-27
Strange! Also strange:
rng(1) ; A = randn(100,3) ;
B1 = A'*A
B2 = mtimes(A',A)
disp(['B1 == B2 : ' '0'+isequal(B2, B1)]) ; % ?????
% but
X = A' ;
C1 = X*A
C2 = mtimes(X,A)
disp(['C1 == C2 : ' '0'+isequal(C1, C2)]) ; % YES!
disp(['C1,C2 == B2 : ' '0'+isequal(C1, C2, B2)]) ;
I first thought that your C is created using MTIMES:
C = A(:,:)'*A(:,:)
disp(['C == B2 : ' '0'+isequal(C, B2)]) ; % but no
disp(['C == B1 : ' '0'+isequal(C, B1)]) ; % also not!!
So there are at least three different results, that should be the same ...
Very puzzling!

类别

Help CenterFile Exchange 中查找有关 Matched Filter and Ambiguity Function 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by