From: Christopher on
Hi,

I've run into an interesting problem with the following code:

x1 = (0 : 95999) / 40e6;
x2 = x1 - mean(x1);
sum(x2)
sum(x2)

As I repeat the sum(x2) command and print out the result, I get slightly different answers, not all of which are zero. I can understand that the result doesn't come out to be exactly zero due to precision issues, but I would like to get the same answer every time. Any ideas what is going on here?

I thought may it was due to the use of threading, if different numbers of threads would interchange the order of operations and hence the final result. But setting maxNumCompThreads to 1 still gives an answer that varies.

Here's some output from the 'ver' command:
MATLAB Version 7.8.0.347 (R2009a)
Operating System: Microsoft Windows XP x64 Version 5.2 (Build 3790: Service Pack 2)

Thanks in advance,
--Chris