How to resolve the algorithm Averages/Pythagorean means step by step in the Smalltalk programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Averages/Pythagorean means step by step in the Smalltalk 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 Smalltalk programming language

Source code in the smalltalk programming language

Collection extend
[
    arithmeticMean
    [
	^ (self fold: [:a :b| a + b ]) / (self size)
    ]

    geometricMean
    [
	^ (self fold: [:a :b| a * b]) raisedTo: (self size reciprocal)
    ]

    harmonicMean
    [
	^ (self size) / ((self collect: [:x|x reciprocal]) fold: [:a :b| a + b ] )
    ]
]

|a|
a := #(1 2 3 4 5 6 7 8 9 10).

a arithmeticMean asFloat displayNl.
a geometricMean asFloat displayNl.
a harmonicMean asFloat displayNl.

((a arithmeticMean) >= (a geometricMean)) displayNl.
((a geometricMean) >= (a harmonicMean)) displayNl.


  

You may also check:How to resolve the algorithm Multiplication tables step by step in the Julia programming language
You may also check:How to resolve the algorithm Numerical integration/Gauss-Legendre Quadrature step by step in the C++ programming language
You may also check:How to resolve the algorithm Test integerness step by step in the Fortran programming language
You may also check:How to resolve the algorithm Harmonic series step by step in the RPL programming language
You may also check:How to resolve the algorithm Soundex step by step in the Raku programming language