How to resolve the algorithm Arithmetic-geometric mean step by step in the ERRE programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Arithmetic-geometric mean step by step in the ERRE programming language

Table of Contents

Problem Statement

Write a function to compute the arithmetic-geometric mean of two numbers.

The arithmetic-geometric mean of two numbers can be (usefully) denoted as

a g m

( a , g )

{\displaystyle \mathrm {agm} (a,g)}

, and is equal to the limit of the sequence: Since the limit of

a

n

g

n

{\displaystyle a_{n}-g_{n}}

tends (rapidly) to zero with iterations, this is an efficient method. Demonstrate the function by calculating:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Arithmetic-geometric mean step by step in the ERRE programming language

Source code in the erre programming language

PROGRAM AGM

!
! for rosettacode.org
!

!$DOUBLE

PROCEDURE AGM(A,G->A)
   LOCAL TA
   REPEAT
      TA=A
      A=(A+G)/2
      G=SQR(TA*G)
   UNTIL A=TA
END PROCEDURE

BEGIN
   AGM(1.0,1/SQR(2)->A)
   PRINT(A)
END PROGRAM


  

You may also check:How to resolve the algorithm Closures/Value capture step by step in the Racket programming language
You may also check:How to resolve the algorithm Loops/Foreach step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Median filter step by step in the BBC BASIC programming language
You may also check:How to resolve the algorithm Roman numerals/Encode step by step in the Phixmonti programming language
You may also check:How to resolve the algorithm Stack step by step in the Julia programming language