How to resolve the algorithm Arithmetic-geometric mean step by step in the Oberon-2 programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Arithmetic-geometric mean step by step in the Oberon-2 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 Oberon-2 programming language
Source code in the oberon-2 programming language
MODULE Agm;
IMPORT
Math := LRealMath,
Out;
CONST
epsilon = 1.0E-15;
PROCEDURE Of*(a,g: LONGREAL): LONGREAL;
VAR
na,ng,og: LONGREAL;
BEGIN
na := a; ng := g;
LOOP
og := ng;
ng := Math.sqrt(na * ng);
na := (na + og) * 0.5;
IF na - ng <= epsilon THEN EXIT END
END;
RETURN ng;
END Of;
BEGIN
Out.LongReal(Of(1,1 / Math.sqrt(2)),0,0);Out.Ln
END Agm.
You may also check:How to resolve the algorithm SHA-1 step by step in the AArch64 Assembly programming language
You may also check:How to resolve the algorithm Strip a set of characters from a string step by step in the PARI/GP programming language
You may also check:How to resolve the algorithm Evolutionary algorithm step by step in the Common Lisp programming language
You may also check:How to resolve the algorithm Comments step by step in the smart BASIC programming language
You may also check:How to resolve the algorithm Hailstone sequence step by step in the Z80 Assembly programming language