Talk:Arithmetic-geometric mean: Difference between revisions
m
Replacxed <lang> tags with <syntaxhighlight>
m (→rapidity: changed some comments and enhanced some IFs, optimized the SQRT function.) |
m (Replacxed <lang> tags with <syntaxhighlight>) |
||
(One intermediate revision by one other user not shown) | |||
Line 39:
The referenced Mathworld page mentions that AGM is meaningful on the complex plane as well.
:It certainly has. It has been called The Mind of God (perhaps beyond the scope of this task!). There is a little more to it than adding +0i to the real solution. In Real Maths sqrt 4 is 2(This task assumes this). In fantasy maths sqrt 4 is 2 and -2. Then the next iteration takes the sqrt of a negative number, and maths goes complex. The result in Complex maths is the set of all these arithmetric geometric means.--[[User:Nigel Galloway|Nigel Galloway]] 14:20, 23 April 2012 (UTC)
<
import (
Line 47:
)
const ε = 1e-14</
==rapidity of convergence==
From this Rosetta Code task's prologue:
Line 55:
:: <big><big>Since the limit of <math>a_n-g_n</math> tends (rapidly) to zero with iterations, this is an efficient method.</big></big>
<br>With this in mind,
<br>added a display of the iteration count along with the number of decimal digits being used.
The modified REXX program is:
<
parse arg a b digs . /*obtain optional numbers from the C.L.*/
if digs=='' | digs=="," then digs=100 /*No DIGS specified? Then use default.*/
Line 70:
agm: procedure: parse arg x,y; if x=y then return x /*is it an equality case? */
if y=0 then return 0 /*is value of Y zero? */
if x=0 then return y /
d=digits(); numeric digits d+5 /*add 5 more digs to ensure convergence*/
tiny='1e-' || (digits() - 1);
ox=x + 1
do #=1 while ox\=x & abs(ox)>tiny;
x=(ox+oy)/2; y=sqrt(ox*oy)
end /*
numeric digits d /*restore numeric digits to original.*/
/*this is the only output displayed ►─┐*/
Line 85 ⟶ 84:
sqrt: procedure; parse arg x; if x=0 then return 0; d=digits(); m.=9; numeric form; h=d+6
numeric digits; parse value format(x,2,1,,0) 'E0' with g 'E' _ .; g=g *.5'e'_ % 2
▲'''outputs''' with a specified number of digits, and with the various outputs being combined/reduced/edited:
<pre>
digits= 100, iterations= 9
Line 101 ⟶ 99:
digits= 51200, iterations= 18
</pre>
==Formulae hidden to most browsers by under-tested cosmetic edits at 21:25, 14 April 2016==
|