FUNCTION
Harmonic
Calculates the harmonic mean of a given population.
Interface
#include <codecogs/statistics/moments/harmonic.h>
using namespace Statistics::Moments;
The harmonic mean of N numbers (where,
) is defined by
(1)
The special cases of and
are therefore given by
(2)
(3)
and so on.
For , the harmonic mean is related to the arithmetic mean, A, and the geometric mean, G, by
(4)
The harmonic mean is the special case of the power mean and is one of the Pythagorean means.
Example 1
#include <codecogs/statistics/moments/harmonic.h>
#include <iostream>
int main()
{
double x[4] = {3.5 , 6.5 , 5.9 , 8.8};
double harm = Stats::Moments::harmonic<double>(4, x);
std::cout << "The population harmonic mean is: " << harm << std::endl;
return 0;
}Output:
The population harmonic mean is:5.53489Parameters
n
the size of the population
data
the actual population data given as an array
Returns
the harmonic mean of a 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.