Re: Strange results for simple calculations
- To: mathgroup at smc.vnet.net
- Subject: [mg109537] Re: Strange results for simple calculations
- From: Alexei Boulbitch <alexei.boulbitch at iee.lu>
- Date: Tue, 4 May 2010 06:29:30 -0400 (EDT)
Hi, Anna, seems to be nothing wrong with your calculation. The fitting you have done is such that the differences with negative values and those with positive accurately compensate one another. This result is obtained "by chance", but it is nothing strange, or pathological. This IIn[70]:= data = {{47.5, 0.01484}, {48.5, 0.01603}, {49.5, 0.017195}, {50.5, 0.0240}, {51.5, 0.033409}, {52.5, 0.0467}, {53.5, 0.05748}, {54.5, 0.063885}, {55.5, 0.071935}, {56.5, 0.0748}, {57.5, 0.07639}, {58.5, 0.07639}, {59.5, 0.0748}, {60.5, 0.069635}, {61.5, 0.0609}, {62.5, 0.05578}, {63.5, 0.05167}, {64.5, 0.0450}, {65.5, 0.0406}, {66.5, 0.0381}, {67.5, 0.03641}}; f = Fit[data, {1, x, x^2, x^3, x^4}, x]; fPts = f /. x -> Transpose[data][[1]]; difs = fPts - Transpose[data][[2]]; Mean[difs] Out[74]= -5.37874*10^-14 returns the value you got. If we however, look at the values of few differences (say, the first to third) they are much larger: In[76]:= difs[[1]] difs[[2]] difs[[3]] Out[76]= -0.000761973 Out[77]= -0.00162336 Out[78]= 0.00182768 So each of them typically is about 0.001. For this reason, if you add, or remove one single point you will have the result immediately about 0.001 instead of about 10^-14. Nothing strange. It is for this reason that in the theory of errors one sums squares of the differences, rather than the values themselves: In[82]:= Sqrt[Mean[difs^2]] Out[82]= 0.00175502 which gives a reasonable estimate for the mean error. Have fun, Alexei Hi All, I have a data which I fit with the polynomial of 4th order and then I want to find the mean of the differences between the data and the model: (* my data, 21 points *) data = {{47.5, 0.01484}, {48.5, 0.01603}, {49.5, 0.017195}, {50.5, 0.0240}, {51.5, 0.033409}, {52.5, 0.0467}, {53.5, 0.05748}, {54.5,0.063885}, {55.5, 0.071935}, {56.5, 0.0748}, {57.5, 0.07639}, {58.5, 0.07639}, {59.5, 0.0748}, {60.5, 0.069635}, {61.5, 0.0609}, {62.5, 0.05578}, {63.5, 0.05167}, {64.5, 0.0450}, {65.5, 0.0406}, {66.5, 0.0381}, {67.5, 0.03641}}; (* polynomial fit *) f = Fit[data, {1, x, x^2, x^3, x^4}, x] (* differences between the data an model *) var = Table[data[[i, 2]] - f /. x -> data[[i, 1]], {i, 1, Length[data]}] (* calculate mean *) Mean[var] My result is: -3.65422*10^-14 which I find "a bit" underestimated. Same goes wrong if I just want to do Sum[var]. Now compare the two loops where the difference is only in the upper limit of the sum 20 or 21: (* loop 1 *) i = 1; a = 0; While[i <= 21, a = a + var[[i]]; i = i + 1; ] a (* loop 2 *) i = 1; a = 0; While[i <= 20, a = a + var[[i]]; i = i + 1; ] a First loop returns -7.67386*10^-13 the second 0.00251855. So, is there something wrong with the last point in my table var? How about I change the initial value of i and let it count till 21, (* loop 3 *) i = 2; a = 0; While[i <= 21, a = a + var[[i]]; i = i + 1; ] a And the result is: -0.000761973! I am completely lost here. Could someone please explain me what I am doing wrong? Cheers Anna