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

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!

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

제품

질문:

2014년 2월 27일

편집:

2014년 2월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by