How to resolve the algorithm Averages/Pythagorean means step by step in the Erlang programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Averages/Pythagorean means step by step in the Erlang 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 Erlang programming language
Source code in the erlang programming language
%% Author: Abhay Jain <abhay_1303@yahoo.co.in>
-module(mean_calculator).
-export([find_mean/0]).
find_mean() ->
%% This is function calling. First argument is the the beginning number
%% and second argument is the initial value of sum for AM & HM and initial value of product for GM.
arithmetic_mean(1, 0),
geometric_mean(1, 1),
harmonic_mean(1, 0).
%% Function to calculate Arithmetic Mean
arithmetic_mean(Number, Sum) when Number > 10 ->
AM = Sum / 10,
io:format("Arithmetic Mean ~p~n", [AM]);
arithmetic_mean(Number, Sum) ->
NewSum = Sum + Number,
arithmetic_mean(Number+1, NewSum).
%% Function to calculate Geometric Mean
geometric_mean(Number, Product) when Number > 10 ->
GM = math:pow(Product, 0.1),
io:format("Geometric Mean ~p~n", [GM]);
geometric_mean(Number, Product) ->
NewProd = Product * Number,
geometric_mean(Number+1, NewProd).
%% Function to calculate Harmonic Mean
harmonic_mean(Number, Sum) when Number > 10 ->
HM = 10 / Sum,
io:format("Harmonic Mean ~p~n", [HM]);
harmonic_mean(Number, Sum) ->
NewSum = Sum + (1/Number),
harmonic_mean(Number+1, NewSum).
You may also check:How to resolve the algorithm Dot product step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Documentation step by step in the PARI/GP programming language
You may also check:How to resolve the algorithm Sorting algorithms/Selection sort step by step in the Delphi programming language
You may also check:How to resolve the algorithm Align columns step by step in the OxygenBasic programming language
You may also check:How to resolve the algorithm Tokenize a string step by step in the V (Vlang) programming language