How to resolve the algorithm Arithmetic-geometric mean step by step in the PL/I programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Arithmetic-geometric mean step by step in the PL/I 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 PL/I programming language
Source code in the pl/i programming language
arithmetic_geometric_mean: /* 31 August 2012 */
procedure options (main);
declare (a, g, t) float (18);
a = 1; g = 1/sqrt(2.0q0);
put skip list ('The arithmetic-geometric mean of ' || a || ' and ' || g || ':');
do until (abs(a-g) < 1e-15*a);
t = (a + g)/2; g = sqrt(a*g);
a = t;
put skip data (a, g);
end;
put skip list ('The result is:', a);
end arithmetic_geometric_mean;
You may also check:How to resolve the algorithm SEDOLs step by step in the Arturo programming language
You may also check:How to resolve the algorithm Copy a string step by step in the Common Lisp programming language
You may also check:How to resolve the algorithm Unbias a random generator step by step in the J programming language
You may also check:How to resolve the algorithm Lucas-Lehmer test step by step in the PARI/GP programming language
You may also check:How to resolve the algorithm Truncate a file step by step in the Ada programming language