scipy.special.agm#

scipy.special.agm(a, b, out=None) = <ufunc 'agm'>#

计算 ab 的算术-几何平均数。

以 a_0 = a 和 b_0 = b 开始,并重复计算

a_{n+1} = (a_n + b_n)/2
b_{n+1} = sqrt(a_n*b_n)

a_n 和 b_n 在 n 增加时收敛到相同的极限值;它们的公共极限值是 agm(a, b)。

参数:
a, barray_like

仅限实值。如果值均为负值,则结果为负值。如果一个值为负值而另一个值为正值,则返回 nan

outndarray,可选

函数值可选输出数组

返回:
标量或 ndarray

ab 的算术-几何平均数。

示例

>>> import numpy as np
>>> from scipy.special import agm
>>> a, b = 24.0, 6.0
>>> agm(a, b)
13.458171481725614

将该结果与迭代进行比较

>>> while a != b:
...     a, b = (a + b)/2, np.sqrt(a*b)
...     print("a = %19.16f  b=%19.16f" % (a, b))
...
a = 15.0000000000000000  b=12.0000000000000000
a = 13.5000000000000000  b=13.4164078649987388
a = 13.4582039324993694  b=13.4581390309909850
a = 13.4581714817451772  b=13.4581714817060547
a = 13.4581714817256159  b=13.4581714817256159

当给出类数组参数时,应用广播

>>> a = np.array([[1.5], [3], [6]])  # a has shape (3, 1).
>>> b = np.array([6, 12, 24, 48])    # b has shape (4,).
>>> agm(a, b)
array([[  3.36454287,   5.42363427,   9.05798751,  15.53650756],
       [  4.37037309,   6.72908574,  10.84726853,  18.11597502],
       [  6.        ,   8.74074619,  13.45817148,  21.69453707]])