How to resolve the algorithm Arithmetic-geometric mean step by step in the Factor programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Arithmetic-geometric mean step by step in the Factor 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 Factor programming language
Source code in the factor programming language
USING: kernel math math.functions prettyprint ;
IN: rosetta-code.arithmetic-geometric-mean
: agm ( a g -- a' g' ) 2dup [ + 0.5 * ] 2dip * sqrt ;
1 1 2 sqrt / [ 2dup - 1e-15 > ] [ agm ] while drop .
You may also check:How to resolve the algorithm Sorting algorithms/Bubble sort step by step in the ALGOL W programming language
You may also check:How to resolve the algorithm Boyer-Moore string search step by step in the Pascal programming language
You may also check:How to resolve the algorithm Hilbert curve step by step in the zkl programming language
You may also check:How to resolve the algorithm Quine step by step in the Perl programming language
You may also check:How to resolve the algorithm Walk a directory/Recursively step by step in the Nanoquery programming language