How to resolve the algorithm Arithmetic-geometric mean step by step in the Standard ML programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Arithmetic-geometric mean step by step in the Standard ML 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 Standard ML programming language
Source code in the standard programming language
fun agm(a, g) = let
fun agm'(a, g, eps) =
if Real.abs(a-g) < eps then
a
else
agm'((a+g)/2.0, Math.sqrt(a*g), eps)
in agm'(a, g, 1e~15)
end;
You may also check:How to resolve the algorithm Compound data type step by step in the Seed7 programming language
You may also check:How to resolve the algorithm Catalan numbers step by step in the Oforth programming language
You may also check:How to resolve the algorithm Almost prime step by step in the Perl programming language
You may also check:How to resolve the algorithm Interactive programming (repl) step by step in the Fōrmulæ programming language
You may also check:How to resolve the algorithm Sparkline in unicode step by step in the Groovy programming language