What's the numerically best way to calculate the average

Tobias Langner picture Tobias Langner · Sep 26, 2011 · Viewed 8.3k times · Source

what's the best way to calculate the average? With this question I want to know which algorithm for calculating the average is the best in a numerical sense. It should have the least rounding errors, should not be sensitive to over- or underflows and so on.

Thank you.


Additional information: incremental approaches preferred since the number of values may not fit into RAM (several parallel calculations on files larger than 4 GB).

Answer

MSalters picture MSalters · Sep 26, 2011

If you want an O(N) algorithm, look at Kahan summation.