Maths Algorithms in C#: Variance
I talked a bit about variance in the post on standard deviation, so this is a little bit a rehash from what I said there.
The variance is obtained by calculating the data set consisting of each data point in the original data set subtracting the arithmetic mean for the data set, and then squaring it.
We then take the arithmetic mean of the deviations, which gives us the variance for our data set.
The full sourcecode for the MathLib library is available at https://github.com/sjmeunier/mathlib
Originally posted on my old blog, Smoky Cogs, on 23 Oct 2009
Updated 5 Oct 2016: Updated code snippet after refactoring MathLib library