Arithmetic-geometric mean: Difference between revisions

Content added Content deleted
m (Removed “$” in line “echo agm(1.0,1.0/sqrt(2.0))”)
Line 2,670: Line 2,670:
{{out}}
{{out}}
<pre>0.84721309</pre>
<pre>0.84721309</pre>

=={{header|Smalltalk}}==
{{works with|Smalltalk/X}}
That is simply a copy/paste of the already existing age method in the Number class:
<lang smalltalk>agm:y
"return the arithmetic-geometric mean agm(x, y) of the receiver (x) and the argument, y.
See https://en.wikipedia.org/wiki/Arithmetic-geometric_mean
and http://www.wolframalpha.com/input/?i=agm(24,+6)"

|ai an gi gn epsilon delta|

ai := (self + y) / 2.
gi := (self * y) sqrt.
epsilon := self ulp.

[
an := (ai + gi) / 2.
gn := (ai * gi) sqrt.
delta := (an - ai) abs.
ai := an.
gi := gn.
] doUntil:[ delta < epsilon ].
^ ai</lang>

<lang smalltalk>Transcript showCR:24 agm:6.
Transcript showCR:(1/2) agm:(1/6).</lang>
{{out}}
<pre>
13.4581714817256
0.310602797207483


=={{header|SQL}}==
=={{header|SQL}}==