English Français Deutsch

Arithmetic-geometric mean

' Write a function to compute the arithmetic-geometric mean of two numbers.

function agm(x,y)
set a = x
set g = y
set i = 0
while abs(a - g) > 0.00000000001
set an = (a + g)/2
set gn = sqrt(a * g)
set a = an
set g = gn
set i = i + 1
end while

set result = g

end function

set x = 1
set y = 1/sqrt(2)
echo (x + y)/2
echo sqrt(x*y)
echo agm(x,y)

Write a function to compute the arithmetic-geometric mean of two numbers.

0.853553390593

0.840896415254

0.847213084794