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

Published on 12 May 2024 09:40 PM

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

Source code in the pari/gp programming language

arithmetic(v)={
  sum(i=1,#v,v[i])/#v
};
geometric(v)={
  prod(i=1,#v,v[i])^(1/#v)
};
harmonic(v)={
  #v/sum(i=1,#v,1/v[i])
};

v=vector(10,i,i);
[arithmetic(v),geometric(v),harmonic(v)]

arithmetic_first(n)={
  (n+1)/2
};
geometric_first(n)={
  n!^(1/n)
};
harmonic_first(n)={
  n/if(n>1000,
    log(n)+Euler+1/(n+n)+1/(12*n^2)-1/(120*n^4)+1/(252*n^6)-1/(240*n^8)+1/(132*n^10)
  ,
    n/sum(k=1,n,1/k)
  )
};

[arithmetic_first(10),geometric_first(10),harmonic_first(10)]
%[1]>=%[2] && %[2] >= %[3]

  

You may also check:How to resolve the algorithm Repeat a string step by step in the BQN programming language
You may also check:How to resolve the algorithm Brace expansion step by step in the Java programming language
You may also check:How to resolve the algorithm Break OO privacy step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Compound data type step by step in the Stata programming language
You may also check:How to resolve the algorithm Pointers and references step by step in the Z80 Assembly programming language