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

Published on 12 May 2024 09:40 PM

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

Source code in the elixir programming language

defmodule Means do
  def arithmetic(list) do
    Enum.sum(list) / length(list)
  end 
  def geometric(list) do
    :math.pow(Enum.reduce(list, &(*/2)), 1 / length(list))
  end 
  def harmonic(list) do
    1 / arithmetic(Enum.map(list, &(1 / &1)))
  end 
end

list = Enum.to_list(1..10)
IO.puts "Arithmetic mean: #{am = Means.arithmetic(list)}"
IO.puts "Geometric mean:  #{gm = Means.geometric(list)}"
IO.puts "Harmonic mean:   #{hm = Means.harmonic(list)}"
IO.puts "(#{am} >= #{gm} >= #{hm}) is #{am >= gm and gm >= hm}"


  

You may also check:How to resolve the algorithm Bulls and cows step by step in the ALGOL 68 programming language
You may also check:How to resolve the algorithm Literals/String step by step in the 6502 Assembly programming language
You may also check:How to resolve the algorithm Feigenbaum constant calculation step by step in the Lambdatalk programming language
You may also check:How to resolve the algorithm Colour pinstripe/Display step by step in the Java programming language
You may also check:How to resolve the algorithm Sorting algorithms/Bogosort step by step in the MATLAB / Octave programming language