Numerical precision of matrix multiplication (inconsistent results with colon indexing)
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
0 Kommentare
Antworten (1)
Jos (10584)
am 27 Feb. 2014
Bearbeitet: Jos (10584)
am 27 Feb. 2014
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!
0 Kommentare
Siehe auch
Kategorien
Mehr zu Matched Filter and Ambiguity Function finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!