I have forgotten

COST (GBP)
1.00
0.00
0

Harmonic

Calculates the harmonic mean of a given population.
Controller: CodeCogs
Contents

C++

Harmonic

 template doubleharmonic( int n T* data )
The harmonic mean of N numbers $\inline&space;x_i$ (where, $\inline&space;i=1,2...,N$) is defined by
$H=\frac{n}{\sum_{i=1}^N\frac{1}{x_i}}$

The special cases of $\inline&space;N=2$ and $\inline&space;N=3$ are therefore given by
$H(x_1,x_2)=\frac{2x_1x_2}{x_1+x_2}$

$H(x_1,x_2,x_3)=\frac{3x_1x_2x_3}{x_1x_2+x_1x_3+x_2x_3},$
and so on.

For $\inline&space;N=2$, the harmonic mean is related to the arithmetic mean, A, and the geometric mean, G, by
$H=\frac{G^2}{A}$

The harmonic mean is the special case $\inline&space;M_{-1}$ 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.53489

Parameters

 n the size of the population data the actual population data given as an array

Returns

the harmonic mean of a given population

Authors

Anca Filibiu (August 2005)
Source Code

Source code is available when you agree to a GP Licence or buy a Commercial Licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.