Functions

agm

Supported By

Syntax

[the] agm of ( expression , expression )

Expression yields an integer, a number, or a complex.

Example

put agm(steve, bill) into andy

Description

The agm function returns the arithmetic-geometric mean of its arguments.

The following function handler mimics the behavior of this built-in function for valid arguments:

function agm a,b
  repeat while a is not b
    put (a+b)/2 into arithmeticMean
    put sqrt(a*b) into geometricMean
    put arithmeticMean into a
    put geometricMean into b
  end repeat
  return a
end agm

The agm function is faster and more accurate than using the above handler.

If both arguments are integers or numbers, a number is returned. If either argument is negative, NaN is returned. To get a complex result, convert the arguments to complexes.

If either argument is a complex, a complex is returned.

Notes

To use this function with more than two arguments, use this construction:

get agm(avg(list), geom(list))