Rounding Errors in Matlab
3 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
James Tursa
on 27 Aug 2015
Edited: James Tursa
on 27 Aug 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).
0 Comments
See Also
Categories
Find more on Multidimensional Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!