How to resolve the algorithm Averages/Pythagorean means step by step in the GAP programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Averages/Pythagorean means step by step in the GAP programming language
Table of Contents
Problem Statement
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.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Averages/Pythagorean means step by step in the GAP programming language
Source code in the gap programming language
# The first two work with rationals or with floats
# (but bear in mind that support of floating point is very poor in GAP)
mean := v -> Sum(v) / Length(v);
harmean := v -> Length(v) / Sum(v, Inverse);
geomean := v -> EXP_FLOAT(Sum(v, LOG_FLOAT) / Length(v));
mean([1 .. 10]);
# 11/2
harmean([1 .. 10]);
# 25200/7381
v := List([1..10], FLOAT_INT);;
mean(v);
# 5.5
harmean(v);
# 3.41417
geomean(v);
# 4.52873
You may also check:How to resolve the algorithm Hello world/Newbie step by step in the COBOL programming language
You may also check:How to resolve the algorithm Floyd-Warshall algorithm step by step in the zkl programming language
You may also check:How to resolve the algorithm Dice game probabilities step by step in the Phix programming language
You may also check:How to resolve the algorithm XML/XPath step by step in the Go programming language
You may also check:How to resolve the algorithm Empty string step by step in the Mercury programming language