Given the size of each number, the rounding error in simple operations on this number is of the order 10^-14
You have 5*10^6 numbers, hence if you are really unlucky the rounding error can become anything upto 5*10^-8.
Your observed error is of size 10^10, which is well in the expected range.
Note that the difference is not caused by the complex transpose, but by the product of the sum vs the matrix product.
A = randn(1,5e6)+1i*randn(1,5e6);
B = randn(1,5e6)+1i*randn(1,5e6);
B1 = conj(B);
B2 = B';
isequal(B1(:),B2(:)) % This returns true
A*transpose(conj(B)) - A*B' % Hence this returns zero
sum(A.*transpose(B')) - A*B' % But this returns something like 1e-10
A similar effect occurs for non complex A
and B
:
N=1e6;
A = 1:N;
B=1:N;
(N * (N + 1) * (2*N + 1))/6 % This will give exactly the right answer
A*B'
fliplr(A)*fliplr(B)'
Note that the two lowest answers only vary a few hundred from eachother, whilst they are actually over 2000 from the correct answer. If this is a problem consider using the symbolic toolbox. That allows you to calculate with arbitrary precision.