Variations of average data between Spin and Microsoft Excel
RussM
Posts: 27
I have a program that collects data from two rotary encoders and outputs the data to excel. My program then sorts the data using bubble sort then takes the average of the 30 highest values. The problem I am facing is that the average calculated in my program is always considerably lower than the average given to me in Excel. For example, if I have 30 data points ranging in values from approximately 2.559 to 2.6069 Excel calculates the average as 2.6019. When I calculate the average of those same points in my program it calculates the average as 2.5153. I have attached my average algorithm, bubble sort algorithm and the program as a whole. Does anyone know why I am getting this data discrepancy? Thanks for any help!
Bubble Sort
Average, note that "i" is equal to the number of elements in my data array.
Bubble Sort
c := 0 d := 0 swap := 0.0 '==Sort values using bubble sory repeat while (c < (i - 1)) d := 0 repeat while (d < (i-c-1) ) if (1 == f32_orig.FCmp(float_highs[d],float_highs[d+1])) swap := float_highs[d] float_highs[d] := float_highs[d+1] float_highs[d+1] := swap d := d + 1 c := c + 1
Average, note that "i" is equal to the number of elements in my data array.
xbar := 0.0 h := 0 an_average := 0.0 repeat while (h < 30) an_average := f32_orig.FAdd(an_average, float_highs[i-h]) h := h + 1 PDAQ.DataText(string("Highs Average")) PDAQ.CR xbar := f32_orig.FDiv(an_average, 30.0) PDAQ.DataText(fs.FloatToString(xbar)) PDAQ.CR
Comments
Where do you see that? I sum up i-0,i-1,i-2,...i-29 which gives me the sum of the 30 highest values.
In that respect my first post was slightly incorrect. However you do include index i which is invalid.
You're absolutely right. That fixed the problem thank you!