error in big matrix multiplication
3 views (last 30 days)
I have two matrices as Q a 4-by-4 matrix and x as a 4-by-10000 matrix . When I compute the multiplication as
Ans1 = Q * x;
the answer is different than having a for loop like
for i = 1 :10000
Ans2(:,i) = Q * x(:,i);
The order of error (Ans1 - Ans2) is 1e-16 for my special case of Q and x. I know it is small but I was wondering what is the source of this error and how I can eliminate it.
Walter Roberson on 3 May 2017
Edited: Walter Roberson on 3 May 2017
The 4*10000 case would be delegated to the highly optimized multi-threaded libraries such as LINPACK or BLAS. The additions could end up being done in a different order, leading to a slightly different round-off result. Also, potentially the highly optimized libraries could use an instruction such as Fused Multiply And Add, which does one fewer rounding operations, potentially leading to a more accurate -- but different -- result.