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

1 回表示 (過去 30 日間)
Matthias Michelsburg
Matthias Michelsburg 2014 年 2 月 27 日
編集済み: Jos (10584) 2014 年 2 月 27 日
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 Center および File ExchangeMatched 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