RosettaCodeData/Task/Arithmetic-geometric-mean/Relation/arithmetic-geometric-mean.r...

19 lines
258 B
Plaintext

function agm(x,y)
set a = x
set g = y
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)