How to resolve the algorithm Arithmetic-geometric mean step by step in the Icon and Unicon programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Arithmetic-geometric mean step by step in the Icon and Unicon 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 Icon and Unicon programming language
Source code in the icon programming language
procedure main(A)
a := real(A[1]) | 1.0
g := real(A[2]) | (1 / 2^0.5)
epsilon := real(A[3])
write("agm(",a,",",g,") = ",agm(a,g,epsilon))
end
procedure agm(an, gn, e)
/e := 1e-15
while abs(an-gn) > e do {
ap := (an+gn)/2.0
gn := (an*gn)^0.5
an := ap
}
return an
end
You may also check:How to resolve the algorithm History variables step by step in the D programming language
You may also check:How to resolve the algorithm Variables step by step in the EasyLang programming language
You may also check:How to resolve the algorithm Leap year step by step in the 11l programming language
You may also check:How to resolve the algorithm Sorting algorithms/Quicksort step by step in the C programming language
You may also check:How to resolve the algorithm Repeat a string step by step in the Objeck programming language