I use sum() function in my code. I find it give different result in different Matlab version, such as Matlab 7.0 and Matlab 7.9. I load data from .mat file and compute sum of a 300dim vector. It gives the same result when computing sum of the first 100dim, but gives different results for the total 300dim. I wonder why? And how to deal with it?
No products are associated with this question.
How different are the results, percent-wise?
It is possible that the underlying algorithm has changed, and of course the order of summation affects things in floating point arithmetic. For example:
>> N = 3e6; >> a = rand(1,N); >> S1 = sum(a); >> S2 = sum(a(randperm(N))); >> (S2-S1)/S1 % Not zero. ans =
Play games and win prizes!Learn more