The geometric mean is similar to the arithmetic mean in that it is a type of average for the data, except it has a rather different way of calculating it.
The geometric mean is defined as the n-th root of the product of each value in the data set, where n is the number of data points in the set. This makes it useful for describing things such as percentage growth.
public static double GeometricMean(double[] data, int items)
{
int i;
double GMean, prod;
prod = 1.0;
for (i = 0; i < items; i++)
{
prod *= data[i];
}
GMean = Math.Pow(prod, (1.0 / (double)items));
return GMean;
}
Related posts:
- Maths algorithms in C#: The median The median is defined as the data point that falls...
- Maths algorithms in C#: The Arithmetic mean The arithmetic mean is defined as the average of a...
- Maths algorithms in C#: Standard deviation Standard deviation is a very common calculation in statistical analysis,...
- Maths algorithms in C#: Variance I talked a bit about variance in the post on...
- Maths algorithms in C#: Linear least squares fit When analysing data it is often useful to find an...
Related posts brought to you by Yet Another Related Posts Plugin.
Serge Meunier is a software developer living in Cape Town, South Africa. He loves programming, fencing, philosophy, feeding his internet addiction, and, of course, dogs.
Comments