Rounding Errors in Matlab

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.

回答 (1 件)

James Tursa
James Tursa 2015 年 8 月 27 日
編集済み: James Tursa 2015 年 8 月 27 日

0 投票

"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).

カテゴリ

ヘルプ センター および File ExchangeMultidimensional Arrays についてさらに検索

質問済み:

2015 年 8 月 27 日

編集済み:

2015 年 8 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by