Rounding Errors in Matlab

1 visualización (últimos 30 días)
Michael
Michael el 27 de Ag. de 2015
Editada: James Tursa el 27 de Ag. de 2015
Hello.
I know there are rounding errors in Matlab due to double precision. But can anybody explain this behaviour?
load('testmatrices.mat')
test = T*U.'-U*T.';
test(1,1)
%ans = 0.0000e+00 + 2.5611e-09i
vector1 = T(1,:);
vector2 = U(1,:);
vector1*vector2.'-vector2*vector1.'
%ans = 0
Why do I get a rounding error for the first calculation, but not for the second one. Shouldn't I get the same rounding error at least? Thank you. Ps: The matrices U and T are attached and I use Matlab2014b 64bit.

Respuestas (1)

James Tursa
James Tursa el 27 de Ag. de 2015
Editada: James Tursa el 27 de Ag. de 2015
"Shouldn't I get the same rounding error at least?"
No, you should not expect this in general. MATLAB uses BLAS library routines in the background to perform matrix multiplication (the * operator). These routines are highly optimized for memory access and speed. They will often examine the sizes of the input variables and then perform the calculations in the "best" order for those particular sizes. So I could easily see the full matrix multiply calculations being ordered differently than the vector multiply calculations, resulting in a slightly different answer for the two cases. In fact, they might not even be using the same underlying routine ... one case might use the BLAS general matrix multiply routine while the other case might use the BLAS dot product routine (this is just a guess ... I would have to run some tests to verify it).

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by