FUNCTION
Geometric
Calculates the geometric mean of a given population.
You're viewing an older version of this page (#5366). View the current version.
Interface
#include <codecogs/statistics/moments/geometric.h>
using namespace Statistics::Moments;
The geometric mean of a sequence $x_i$ is defined by:
$$G=\sqrt[N]{\prod_{i=1}^N x_i}$$
(1)
Thus,
$$G(x_1,x_2)=\sqrt{x_1x_2}$$
(2)
$$G(x_1,x_2,x_3)=\sqrt[3]{x_1x_2x_3}$$
(3)
and so on. For $N=2$, the geometric mean is related to the arithmetic mean and harmonic mean by
$$G=\sqrt{AH}$$
(4)
where:
- A = arithmetic mean and
- H = harmonic mean
Example 1
#include <codecogs/statistics/moments/geometric.h>
#include <iostream>
#include<math.h>
int main()
{
int x[5] = {4 , 6 , 1 , 3 , 7};
double geom = Statistics::Moments::geometric(5, x);
std::cout << "The population mean is: " << geom << std::endl;
return 0;
}Output:
The population mean is: 3.47125Parameters
n
the size of the population
data
the actual population data given as an array
Returns
return value the geometric mean of the given population
This function's source code is only visible to registered users — documentation and the calculator above are free to use either way. Sign in to see it.