Arithmetic-geometric mean: Difference between revisions

Rewrite task description for better clarity
No edit summary
(Rewrite task description for better clarity)
Line 1:
{{draft task}} see http://mathworld.wolfram.com/{{wikipedia|Arithmetic-GeometricMean.htmlgeometric mean}}
Write a function to compute the [[wp:Arithmetic-geometric mean|arithmetic-geometric mean]] of two numbers.
[http://mathworld.wolfram.com/Arithmetic-GeometricMean.html]
The arithmetic-geometric mean of two numbers can be (usefully) denoted as <math>\mathrm{agm}(a,g)</math>, and is equal to the limit of the sequence:
: <math>a_0 = a; \qquad g_0 = g</math>
: <math>a_{n+1} = \tfrac{1}{2}(a_n + g_n); \quad g_{n+1} = \sqrt{a_n g_n}.</math>
Since the limit of <math>a_n-g_n</math> tends (rapidly) to zero with iterations, this is an efficient method.
 
Demonstrate the function by calculating:
agm(a,b) is the limit of the arithmetic-geometric mean iteration applied repeatedly starting with a and b: a_0=a, b_0=b, a_{n+1}=(a_n+b_n)/2, b_{n+1}=sqrt(a_n*b_n).
:<math>\mathrm{agm}(1,1/\sqrt{2})</math>
 
The task is to calculate:
 
:<math>agm(1,1/\sqrt{2})</math>
 
=={{header|C++}}==
Anonymous user