Task[edit]
Compute all three of the Pythagorean means of the set of integers 1 through 10 (inclusive).

Show that 



A
(

x

1


,
…
,

x

n


)
≥
G
(

x

1


,
…
,

x

n


)
≥
H
(

x

1


,
…
,

x

n


)


{\displaystyle A(x_{1},\ldots ,x_{n})\geq G(x_{1},\ldots ,x_{n})\geq H(x_{1},\ldots ,x_{n})}

 for this set of positive integers.

 The most common of the three means, the arithmetic mean, is the sum of the list divided by its length:
 



A
(

x

1


,
…
,

x

n


)
=




x

1


+
⋯
+

x

n



n




{\displaystyle A(x_{1},\ldots ,x_{n})={\frac {x_{1}+\cdots +x_{n}}{n}}}


 The geometric mean is the 



n


{\displaystyle n}

th root of the product of the list:
 



G
(

x

1


,
…
,

x

n


)
=




x

1


⋯

x

n




n





{\displaystyle G(x_{1},\ldots ,x_{n})={\sqrt[{n}]{x_{1}\cdots x_{n}}}}


 The harmonic mean is 



n


{\displaystyle n}

 divided by the sum of the reciprocal of each item in the list:
 



H
(

x

1


,
…
,

x

n


)
=


n



1

x

1




+
⋯
+


1

x

n









{\displaystyle H(x_{1},\ldots ,x_{n})={\frac {n}{{\frac {1}{x_{1}}}+\cdots +{\frac {1}{x_{n}}}}}}




See also
Tasks for calculating statistical measures



in one go
moving (sliding window)
moving (cumulative)

Mean
Arithmetic

Statistics/Basic
Averages/Arithmetic mean
Averages/Pythagorean means


Averages/Simple moving average




Geometric

Averages/Pythagorean means




Harmonic

Averages/Pythagorean means




Quadratic

Averages/Root mean square




Circular

Averages/Mean angle
Averages/Mean time of day




Median

Averages/Median




Mode

Averages/Mode




Standard deviation

Statistics/Basic



Cumulative standard deviation






MODULE PythagoreanMeans;
FROM FormatString IMPORT FormatString;
FROM LongMath IMPORT power;
FROM LongStr IMPORT RealToStr;
FROM Terminal IMPORT WriteString,WriteLn,ReadChar;
 
PROCEDURE ArithmeticMean(numbers : ARRAY OF LONGREAL) : LONGREAL;
VAR
    i,cnt : CARDINAL;
    mean : LONGREAL;
BEGIN
    mean := 0.0;
    cnt := 0;
    FOR i:=0 TO HIGH(numbers) DO
        mean := mean + numbers[i];
        INC(cnt);
    END;
    RETURN mean / LFLOAT(cnt)
END ArithmeticMean;
 
PROCEDURE GeometricMean(numbers : ARRAY OF LONGREAL) : LONGREAL;
VAR
    i,cnt : CARDINAL;
    mean : LONGREAL;
BEGIN
    mean := 1.0;
    cnt := 0;
    FOR i:=0 TO HIGH(numbers) DO
        mean := mean * numbers[i];
        INC(cnt);
    END;
    RETURN power(mean, 1.0 / LFLOAT(cnt))
END GeometricMean;
 
PROCEDURE HarmonicMean(numbers : ARRAY OF LONGREAL) : LONGREAL;
VAR
    i,cnt : CARDINAL;
    mean : LONGREAL;
BEGIN
    mean := 0.0;
    cnt := 0;
    FOR i:=0 TO HIGH(numbers) DO
        mean := mean + ( 1.0 / numbers[i]);
        INC(cnt);
    END;
    RETURN LFLOAT(cnt) / mean
END HarmonicMean;
 
 
CONST Size = 10;
TYPE DA = ARRAY[1..Size] OF LONGREAL;
 
VAR
    buf : ARRAY[0..63] OF CHAR;
    array : DA;
    arithmetic,geometric,harmonic : LONGREAL;
BEGIN
    array := DA{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0};
 
    arithmetic := ArithmeticMean(array);
    geometric := GeometricMean(array);
    harmonic := HarmonicMean(array);
 
    WriteString("A = ");
    RealToStr(arithmetic, buf);
    WriteString(buf);
    WriteString(" G = ");
    RealToStr(geometric, buf);
    WriteString(buf);
    WriteString(" H = ");
    RealToStr(harmonic, buf);
    WriteString(buf);
    WriteLn;
 
    FormatString("A >= G is %b, G >= H is %b\n", buf, arithmetic >= geometric, geometric >= harmonic);
    WriteString(buf);
 
    ReadChar
END PythagoreanMeans.