Anonymous user
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}}
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:
:<math>\mathrm{agm}(1,1/\sqrt{2})</math>▼
▲:<math>agm(1,1/\sqrt{2})</math>
=={{header|C++}}==
|