matrix transpose multiplication precision
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi everyone,
Forgive me if this is a stupid question. Is there a loss of precision when Matlab calculates the multiplication of the transpose of a matrix and itself?
for example, set variable q to a 2d matrix of size 6x6 with value 0.9 for each element. The result of q'*q is different than (q+0)'*q.
if true
% code
q = .9*ones(6,6);
norm((q+0)'*q - q'*q)
end
returns:
ans =
5.3291e-015
However a 5x5 matrix is alright:
if true
% code
q = .9*ones(5,5);
norm((q+0)'*q - q'*q)
end
A "whos" of q reveals:
whos qq Name Size Bytes Class Attributes
qq 6x6 288 double
Thanks, Afro
0 Kommentare
Akzeptierte Antwort
James Tursa
am 5 Sep. 2013
Bearbeitet: James Tursa
am 5 Sep. 2013
MATLAB uses BLAS routines to do matrix multiplication. There are separate routines available for generic matrix multiplication and symmetric matrix multiplication. In your case, the MATLAB parser recognizes q'*q as a symmetric matrix multiply and will call the symmetric matrix multiply routine (only calculates about 1/2 the answer and then fills in the rest with copies, which is faster). But for the (q+0)'*q case the parser does not recognize the symmetry of the multiply so it calls the generic matrix multiply routine instead. Slightly different code can produce slightly different results, which is to be expected for floating point arithmetic. Both are "correct".
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!