matrix transpose multiplication precision

2 visualizaciones (últimos 30 días)
Hisham
Hisham el 5 de Sept. de 2013
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

Respuesta aceptada

James Tursa
James Tursa el 5 de Sept. de 2013
Editada: James Tursa el 5 de Sept. de 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".

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by