Talk:Arithmetic-geometric mean: Difference between revisions

Content added Content deleted
(→‎Complex: new section)
Line 32: Line 32:


--[[User:Nigel Galloway|Nigel Galloway]] 14:26, 29 March 2012 (UTC)
--[[User:Nigel Galloway|Nigel Galloway]] 14:26, 29 March 2012 (UTC)

== Complex ==

I'll retract my complex number solution. I don't have a reference for this code and even if the AGM is defined to use a certain root, I'm not sure this code is sufficient. Description and code copied here:

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)
<lang go>package main

import (
"fmt"
"math"
"math/cmplx"
)

const ε = 1e-14

func agm(a, g complex128) complex128 {
for cmplx.Abs(a-g) > cmplx.Abs(a)*ε {
a, g = (a+g)*.5, cmplx.Rect(math.Sqrt(cmplx.Abs(a)*cmplx.Abs(g)),
(cmplx.Phase(a)+cmplx.Phase(g))*.5)
}
return a
}

func main() {
fmt.Println(agm(1, 1/math.Sqrt2))
}</lang>

End of copy --[[User:Sonia|Sonia]] ([[User talk:Sonia|talk]]) 19:16, 17 June 2013 (UTC)