SciPy 1.12 中文文档(四十九)
scipy.special.pro_cv
原文:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.pro_cv.html#scipy.special.pro_cv
scipy.special.pro_cv(m, n, c, out=None) = <ufunc 'pro_cv'>
椭圆体函数特征值
计算椭圆体波函数特征值,顺序为 m,n(n≥m),椭圆体参数 c。
参数:
m array_like
非负参数模式 m
n array_like
参数模式 n(≥ m)
c array_like
球形参数
out ndarray,可选
函数结果的可选输出数组
返回:
cv 标量或 ndarray
特征值
scipy.special.obl_cv
原文:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.obl_cv.html#scipy.special.obl_cv
scipy.special.obl_cv(m, n, c, out=None) = <ufunc 'obl_cv'>
椭球体函数特征值
计算椭球体波函数的特征值,阶数为m、n(n>=m),椭球体参数为c。
参数:
marray_like
模式参数 m(非负)
narray_like
模式参数 n(>= m)
carray_like
椭球体参数
outndarray,可选
函数结果的可选输出数组
返回值:
cv标量或 ndarray
特征值
scipy.special.pro_cv_seq
scipy.special.pro_cv_seq(m, n, c)
椭圆体波函数特征值。
计算模式 m 和 n’=m..n 的椭圆体波函数的一系列特征值,以及椭圆体参数 c。
参考文献
[1]
张善杰、金建明著,“特殊函数的计算”,John Wiley and Sons,1996。people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html
scipy.special.obl_cv_seq
scipy.special.obl_cv_seq(m, n, c)
椭圆体波函数的特征值。
计算椭圆体波函数的特征值序列,对于模式 m 和 n’=m..n 以及椭圆体参数 c。
参考文献
[1]
张善杰、金建明,“特殊函数的计算”,John Wiley and Sons 出版,1996 年。people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html
scipy.special.pro_ang1_cv
scipy.special.pro_ang1_cv(m, n, c, cv, x, out=None) = <ufunc 'pro_ang1_cv'>
长圆体角函数 pro_ang1 用于预计算的特征值
计算长圆体第一类角函数及其导数(相对于 x)的值,对于模参数 m>=0 和 n>=m,球面参数 c 和 |x| < 1.0。需要预先计算的特征值。
参数:
m类似数组
非负模参数 m
n类似数组
模参数 n (>= m)
c类似数组
球面参数
cv类似数组
特征值
x类似数组
实参数 (|x| < 1.0)
outndarray,可选
用于函数结果的可选输出数组
返回:
s标量或 ndarray
函数的值
sp标量或 ndarray
对 x 的导数值
scipy.special.pro_rad1_cv
scipy.special.pro_rad1_cv(m, n, c, cv, x, out=None) = <ufunc 'pro_rad1_cv'>
长椭球径向函数 pro_rad1 的特征值预计算值
计算第一类长椭球径向函数及其在 x 上的导数(对于模式参数 m≥0 和 n≥m,椭球参数 c 和 |x| < 1.0)。需要预先计算特征值。
参数:
m array_like
非负模式参数 m
n array_like
模式参数 n(≥ m)
c array_like
椭球参数
cv array_like
特征值
x array_like
实数参数(|x| < 1.0)
out ndarray,可选
函数结果的可选输出数组
返回值:
s 标量或者 ndarray
函数值
sp 标量或者 ndarray
对 x 的导数值
scipy.special.pro_rad2_cv
scipy.special.pro_rad2_cv(m, n, c, cv, x, out=None) = <ufunc 'pro_rad2_cv'>
预计算特征值的第二类椭圆旋转体径向函数 pro_rad2
计算第二类椭圆旋转体径向函数及其在模式参数 m>=0 和 n>=m、椭圆参数c以及|x| < 1.0(相对于x)的导数。需要预先计算的特征值。
参数:
m类似数组
非负模式参数 m
n类似数组
模式参数 n(>= m)
c类似数组
椭圆参数
cv类似数组
特征值
x类似数组
实参数(|x| < 1.0)
outndarray,可选
函数结果的可选输出数组
返回值:
s标量或 ndarray
函数值
sp标量或 ndarray
对于 x 的导数值
scipy.special.obl_ang1_cv
scipy.special.obl_ang1_cv(m, n, c, cv, x, out=None) = <ufunc 'obl_ang1_cv'>
钝形球面角函数 obl_ang1 对预先计算的特征值的角度
计算钝形球面角函数的第一类及其导数(关于 x),对于模式参数 m>=0 和 n>=m,球体参数 c 和 |x| < 1.0。需要预先计算的特征值。
参数:
m类似数组
模式参数 m (非负)
n类似数组
模式参数 n (>= m)
c类似数组
球体参数
cv类似数组
特征值
x类似数组
参数 x (|x| < 1.0)
out数组,可选
可选的输出数组,用于函数结果
返回:
s标量或者数组
函数值
sp标量或者数组
导数值 vs x
参见
obl_ang1
scipy.special.obl_rad1_cv
scipy.special.obl_rad1_cv(m, n, c, cv, x, out=None) = <ufunc 'obl_rad1_cv'>
预先计算的特征值的椭球体径向函数 obl_rad1
计算第一类椭球体径向函数及其关于x的导数(对于模式参数 m>=0 和 n>=m,椭球参数c和|x| < 1.0)。需要预先计算的特征值。
参数:
marray_like
模式参数 m(非负)
narray_like
模式参数 n (>= m)
carray_like
椭球体参数
cvarray_like
特征值
xarray_like
参数 x (|x| < 1.0)
outndarray,可选
可选的输出数组用于函数结果
返回:
s标量或 ndarray
函数值
sp标量或 ndarray
导数值 vs x
另请参阅
obl_rad1
scipy.special.obl_rad2_cv
scipy.special.obl_rad2_cv(m, n, c, cv, x, out=None) = <ufunc 'obl_rad2_cv'>
预计算特征值的椭球体径向函数 obl_rad2。
计算椭球体径向函数的第二类及其导数(相对于 x),适用于模式参数 m>=0 和 n>=m,椭球体参数 c 和 |x| < 1.0。需要预先计算好的特征值。
参数:
m array_like
模式参数 m (非负)
n array_like
模式参数 n (>= m)
c array_like
椭球体参数
cv array_like
特征值
x array_like
参数 x (|x| < 1.0)
out ndarray, 可选
可选的输出数组用于函数结果。
返回值:
s 标量或者 ndarray
函数值
sp 标量或者 ndarray
导数值 vs x
参见
obl_rad2
scipy.special.kelvin
原文链接:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.kelvin.html#scipy.special.kelvin
scipy.special.kelvin(x, out=None) = <ufunc 'kelvin'>
开尔文函数作为复数
参数:
xarray_like
参数
out ndarray 元组,可选
函数值的可选输出数组
返回值:
Be, Ke, Bep, Kep4-元组,标量或 ndarray
元组(Be, Ke, Bep, Kep)包含复数,表示在x处评估的实部和虚部开尔文函数及其导数。例如,kelvin(x)[0].real = ber x 和 kelvin(x)[0].imag = bei x,ker 和 kei 类似。
scipy.special.kelvin_zeros
scipy.special.kelvin_zeros(nt)
计算所有 Kelvin 函数的 nt 个零点。
返回长度为 nt 的数组元组,包含(ber, bei, ker, kei, ber’, bei’, ker’, kei’)的零点数组。
参考文献
[1]
张善杰、金建明。“特殊函数的计算”,John Wiley and Sons 出版,1996 年。people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html
scipy.special.ber
原文:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.ber.html#scipy.special.ber
scipy.special.ber(x, out=None) = <ufunc 'ber'>
凯尔文函数 ber。
定义如下
[\mathrm{ber}(x) = \Re[J_0(x e^{3 \pi i / 4})]]
其中 (J_0) 是零阶第一类贝塞尔函数(见 jv)。详见 [dlmf] 获取更多详情。
参数:
xarray_like
实数参数。
outndarray,可选
函数结果的可选输出数组。
返回:
标量或者 ndarray
凯尔文函数的值。
另请参见
bei
对应的实部
berp
bei 的导数
jv
第一类贝塞尔函数
参考
[dlmf]
NIST, 数字数学函数库, dlmf.nist.gov/10.61
示例
它可以用贝塞尔函数表示。
>>> import numpy as np
>>> import scipy.special as sc
>>> x = np.array([1.0, 2.0, 3.0, 4.0])
>>> sc.jv(0, x * np.exp(3 * np.pi * 1j / 4)).real
array([ 0.98438178, 0.75173418, -0.22138025, -2.56341656])
>>> sc.ber(x)
array([ 0.98438178, 0.75173418, -0.22138025, -2.56341656])
scipy.special.bei
原文:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.bei.html#scipy.special.bei
scipy.special.bei(x, out=None) = <ufunc 'bei'>
函数 bei 的开尔文函数。
定义如下
[\mathrm{bei}(x) = \Im[J_0(x e^{3 \pi i / 4})]]
其中 (J_0) 是第一类零阶贝塞尔函数(参见 jv)。详细信息请参见 [dlmf]。
参数:
xarray_like
实参数。
outndarray,可选
可选的输出数组用于函数的结果。
返回:
标量或者 ndarray
开尔文函数的值。
另请参阅
对应的实部
bei 的导数
第一类贝塞尔函数
参考文献
[dlmf]
NIST, 数学函数数字图书馆, dlmf.nist.gov/10.61
示例
可以用贝塞尔函数表达。
>>> import numpy as np
>>> import scipy.special as sc
>>> x = np.array([1.0, 2.0, 3.0, 4.0])
>>> sc.jv(0, x * np.exp(3 * np.pi * 1j / 4)).imag
array([0.24956604, 0.97229163, 1.93758679, 2.29269032])
>>> sc.bei(x)
array([0.24956604, 0.97229163, 1.93758679, 2.29269032])
scipy.special.berp
原文:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.berp.html#scipy.special.berp
scipy.special.berp(x, out=None) = <ufunc 'berp'>
ber 函数的导数。
参数:
xarray_like
实数参数。
outndarray,可选
函数结果的可选输出数组。
返回值:
标量或者 ndarray
ber 的导数值。
参见
ber
参考文献
[dlmf]
NIST, 数学函数数字图书馆, dlmf.nist.gov/10#PT5
scipy.special.beip
原文链接:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.beip.html#scipy.special.beip
scipy.special.beip(x, out=None) = <ufunc 'beip'>
Kelvin 函数 bei 的导数。
参数:
xarray_like
实数参数。
outndarray,可选
可选的输出数组,用于函数的结果。
返回值:
标量或者 ndarray
bei 的导数的值。
参见
参考资料
[dlmf]
美国国家标准与技术研究院,数学函数数字图书馆,dlmf.nist.gov/10#PT5
scipy.special.ker
原文链接:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.ker.html#scipy.special.ker
scipy.special.ker(x, out=None) = <ufunc 'ker'>
凯尔文函数 ker。
定义如下
[\mathrm{ker}(x) = \Re[K_0(x e^{\pi i / 4})]]
其中 (K_0) 是第二类修正贝塞尔函数(参见kv)。更多详细信息请见[dlmf]。
参数:
xarray_like
实数参数。
outndarray, 可选
函数结果的可选输出数组。
返回值:
标量或者 ndarray
凯尔文函数的值。
另请参阅
kei
相应的虚部
kerp
凯尔函数的导数
kv
第二类修正贝塞尔函数
参考文献
[dlmf]
NIST, 数学函数数字图书馆,dlmf.nist.gov/10.61
示例
可用第二类修正贝塞尔函数表示。
>>> import numpy as np
>>> import scipy.special as sc
>>> x = np.array([1.0, 2.0, 3.0, 4.0])
>>> sc.kv(0, x * np.exp(np.pi * 1j / 4)).real
array([ 0.28670621, -0.04166451, -0.06702923, -0.03617885])
>>> sc.ker(x)
array([ 0.28670621, -0.04166451, -0.06702923, -0.03617885])
scipy.special.kei
原文链接:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.kei.html#scipy.special.kei
scipy.special.kei(x, out=None) = <ufunc 'kei'>
开尔文函数 kei。
定义为
[\mathrm{kei}(x) = \Im[K_0(x e^{\pi i / 4})]]
其中 (K_0) 是第二类修正贝塞尔函数(参见 kv)。有关更多详细信息,请参见[dlmf]。
参数:
xarray_like
实部参数。
outndarray,可选
函数结果的可选输出数组。
返回:
标量或 ndarray
开尔文函数的值。
另见
相应的实部
kei 的导数
第二类修正贝塞尔函数
参考文献
[dlmf]
NIST,数学函数数字图书馆,dlmf.nist.gov/10.61
示例
它可以用第二类修正贝塞尔函数表示。
>>> import numpy as np
>>> import scipy.special as sc
>>> x = np.array([1.0, 2.0, 3.0, 4.0])
>>> sc.kv(0, x * np.exp(np.pi * 1j / 4)).imag
array([-0.49499464, -0.20240007, -0.05112188, 0.0021984 ])
>>> sc.kei(x)
array([-0.49499464, -0.20240007, -0.05112188, 0.0021984 ])
scipy.special.kerp
原文:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.kerp.html#scipy.special.kerp
scipy.special.kerp(x, out=None) = <ufunc 'kerp'>
ker 函数的导数。
参数:
x数组样
实数参数。
out数组, 可选
函数结果的可选输出数组。
返回值:
标量或数组
ker的导数值。
另请参见
ker
参考文献
[dlmf]
美国国家标准技术研究所,数学函数数字图书馆,dlmf.nist.gov/10#PT5
scipy.special.keip
原文:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.keip.html#scipy.special.keip
scipy.special.keip(x, out=None) = <ufunc 'keip'>
Kelvin 函数 kei 的导数。
参数:
x 类似数组
实数参数。
out ndarray,可选
函数结果的可选输出数组。
返回:
标量或者 ndarray
kei 的导数的值。
另见
参考
[dlmf]
NIST,数字数学函数数字库,dlmf.nist.gov/10#PT5
scipy.special.ber_zeros
scipy.special.ber_zeros(nt)
计算 Kelvin 函数 ber 的 nt 个零点。
参数:
ntint
计算的零点数量。必须为正数。
返回值:
ndarray
首 nt 个 Kelvin 函数的零点。
另见
ber
参考文献
[1]
Zhang, Shanjie 和 Jin, Jianming。“特殊函数的计算”,John Wiley and Sons,1996 年。people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html
scipy.special.bei_zeros
scipy.special.bei_zeros(nt)
计算 Kelvin 函数bei的 nt 个零点。
参数:
nt int
需要计算的零点数量。必须是正数。
返回:
ndarray
第一 nt 个 Kelvin 函数的零点。
另请参阅
bei
参考文献:
[1]
Zhang, Shanjie 和 Jin, Jianming. “特殊函数的计算”, John Wiley and Sons, 1996. people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html
scipy.special.berp_zeros
scipy.special.berp_zeros(nt)
计算 Kelvin 函数 ber 的导数的nt个零点。
参数:
ntint
需要计算的零点数。必须为正数。
返回:
ndarray
第nt个 Kelvin 函数导数的零点。
另见
ber, berp
参考文献
[1]
张, 善杰 和 金, 建明. “特殊函数的计算”, 约翰·威利和儿子, 1996. people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html
scipy.special.beip_zeros
scipy.special.beip_zeros(nt)
计算 Kelvin 函数 bei 的导数的 nt 个零点。
参数:
ntint
需要计算的零点数量。必须是正数。
返回:
ndarray
Kelvin 函数导数的前 nt 个零点。
另见
参考文献
[1]
张善杰和金建明。“特殊函数的计算”,John Wiley and Sons,1996。people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html
scipy.special.ker_zeros
scipy.special.ker_zeros(nt)
计算 Kelvin 函数 ker 的 nt 个零点。
参数:
ntint
要计算的零点数。必须是正数。
返回结果:
ndarray
Kelvin 函数的前 nt 个零点。
另请参见
ker
参考文献
[1]
Zhang, Shanjie 和 Jin, Jianming. “计算特殊函数”, John Wiley and Sons, 1996. people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html
scipy.special.kei_zeros
scipy.special.kei_zeros(nt)
计算开尔文函数 kei 的 nt 个零点。
参数:
ntint
要计算的零点数目。必须是正数。
返回:
ndarray
第一个 nt 个开尔文函数的零点。
参见
kei
参考文献
[1]
Zhang, Shanjie 和 Jin, Jianming. “特殊函数的计算”, John Wiley and Sons, 1996. people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html
scipy.special.kerp_zeros
scipy.special.kerp_zeros(nt)
计算 Kelvin 函数 ker 的导数的 nt 个零点。
参数:
ntint
需要计算的零点数量。必须是正数。
返回值:
ndarray
Kelvin 函数导数的前 nt 个零点。
另请参阅
ker, kerp
References
[1]
张栅杰和金建明的著作《特殊函数计算》,John Wiley and Sons, 1996. people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html
scipy.special.keip_zeros
scipy.special.keip_zeros(nt)
计算凯尔文函数 kei 导数的 nt 个零点。
参数:
ntint
需要计算的零点数。必须是正数。
返回值:
ndarray
第一个 nt 个凯尔文函数导数的零点。
另见
参考资料
[1]
张善杰,金建明。《特殊函数的计算》,John Wiley and Sons,1996 年。people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html
scipy.special.comb
原文:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.comb.html#scipy.special.comb
scipy.special.comb(N, k, *, exact=False, repetition=False, legacy=<object object>)
每次取 N 个事物中 k 个的组合数。
这通常表示为“N 选 k”。
参数:
N整数,ndarray
事物的数量。
k整数,ndarray
取元素的数量。
exact布尔值,可选
对于整数,如果exact为 False,则使用浮点精度,否则结果将精确计算。对于非整数,如果exact为 True,则忽略。
repetition布尔值,可选
如果repetition为 True,则计算带重复的组合数。
legacy布尔值,可选
如果legacy为 True 且exact为 True,则非整数参数被转换为整数;如果legacy为 False,则非整数参数的结果不受exact值影响。
自版本 1.9.0 起已弃用:使用legacy已被弃用,并将在 Scipy 1.14.0 中移除。如果要保留旧版行为,请直接转换输入,例如comb(int(your_N), int(your_k), exact=True)。
返回:
val整数,浮点数,ndarray
组合总数。
参见
binom
二项式系数作为两个实变量的函数。
注意
-
仅在 exact=False 情况下接受数组参数。
-
如果 N < 0 或 k < 0,则返回 0。
-
如果 k > N 且 repetition=False,则返回 0。
示例
>>> import numpy as np
>>> from scipy.special import comb
>>> k = np.array([3, 4])
>>> n = np.array([10, 10])
>>> comb(n, k, exact=False)
array([ 120., 210.])
>>> comb(10, 3, exact=True)
120
>>> comb(10, 3, exact=True, repetition=True)
220
scipy.special.perm
原文链接:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.perm.html#scipy.special.perm
scipy.special.perm(N, k, exact=False)
N 个物品中取 k 个的排列,即 k-permutations of N。
也称为“部分排列”。
参数:
N整数,数组
事物的数量。
k整数,数组
取出元素的数量。
exact布尔值,可选
如果 exact 为 False,则使用浮点数精度计算,否则使用精确的长整数计算。
返回:
val整数,数组
N 个物品中取 k 个的排列数。
注释
-
仅对 exact=False 情况接受数组参数。
-
如果 k > N,N < 0,或者 k < 0,则返回 0。
示例
>>> import numpy as np
>>> from scipy.special import perm
>>> k = np.array([3, 4])
>>> n = np.array([10, 10])
>>> perm(n, k)
array([ 720., 5040.])
>>> perm(10, 3, exact=True)
720
scipy.special.stirling2
scipy.special.stirling2(N, K, *, exact=False)
生成第二类斯特林数。
第二类斯特林数计算如下:将 N 个元素的集合分成 K 个非空子集的方式数量。
此函数返回的值是使用动态规划计算的,可以避免在解决方案的子问题中进行冗余计算。对于类似数组的输入,此实现还避免了在不同斯特林数计算中进行冗余计算。
有时这些数字被表示为
[{N \brace{K}}]
详细信息请参见[1]。通常口语表达为“N 子集 K”。
参数:
Nint,ndarray
东西数量。
Kint,ndarray
采取非空子集的数量。
exactbool,可选
使用动态规划(DP)与浮点数处理较小的数组,并使用 Temme 的二阶近似处理更大的N和K输入,可以在速度和精度之间进行权衡。详细描述请参见[2]。对于n > 50,使用 Temme 近似。DP 的最大相对误差为4.510^-16*(n <= 50),Temme 近似的最大相对误差为510^-5*(51 <= n < 70)和910^-6*(70 <= n < 101)。请注意,随着n的增加,这些最大相对误差会进一步减小。
返回:
valint,float,ndarray
分区数。
参见
comb
N 件东西中取 k 件的组合数。
注意事项
-
如果 N < 0 或者 K < 0,则返回 0。
-
如果 K > N,则返回 0。
输出类型始终为int或对象的 ndarray。输入必须包含 numpy 或 python 整数,否则会引发 TypeError。
参考文献
R. L. Graham, D. E. Knuth and O. Patashnik, “Concrete Mathematics: A Foundation for Computer Science,” Addison-Wesley Publishing Company, Boston, 1989. 第六章,第 258 页。
[2]
Temme, Nico M. “Stirling numbers 的渐近估计.” 应用数学研究 89.3 (1993): 233-243。
示例
>>> import numpy as np
>>> from scipy.special import stirling2
>>> k = np.array([3, -1, 3])
>>> n = np.array([10, 10, 9])
>>> stirling2(n, k)
array([9330, 0, 3025], dtype=object)
scipy.special.lambertw
scipy.special.lambertw(z, k=0, tol=1e-8)
莱姆伯特 W 函数。
莱姆伯特 W 函数*W(z)*被定义为w * exp(w)的反函数。换句话说,W(z)的值是这样的,即z = W(z) * exp(W(z))对于任意复数z成立。
莱姆伯特 W 函数是一个具有无限多个分支的多值函数。每个分支给出方程z = w exp(w)的一个单独解。在这里,分支由整数k索引。
参数:
zarray_like
输入参数。
kint,可选
分支索引。
tolfloat,可选
评估容限。
返回:
warray
w将与z具有相同的形状。
另请参阅
wrightomega
莱特Ω函数
注解
所有分支都由lambertw支持:
-
lambertw(z)给出主要解(分支 0) -
lambertw(z, k)在k分支上给出解决方案
莱姆伯特 W 函数有两个部分实数分支:主分支(k = 0)对于实数z > -1/e是实数的,而k = -1分支对于-1/e < z < 0是实数的。除k = 0外的所有分支在z = 0处有对数奇点。
可能问题
评估在接近分支点-1/e时可能变得不精确。在某些极端情况下,lambertw目前可能无法收敛,或者可能进入错误的分支。
算法
使用 Halley 迭代来反转w * exp(w),使用一阶渐近逼近(O(log(w))或O(w))作为初始估计。
分支的定义、实现和选择基于[2]。
参考文献
[1]
zh.wikipedia.org/wiki/%E8%8E%B1%E5%A7%86%E8%B4%9D%E5%B0%94%E5%87%BD%E6%95%B0
[2]
Corless 等人,“关于莱姆伯特 W 函数”,Adv. Comp. Math. 5(1996)329-359。cs.uwaterloo.ca/research/tr/1993/03/W.pdf
示例
莱姆伯特 W 函数是w exp(w)的反函数:
>>> import numpy as np
>>> from scipy.special import lambertw
>>> w = lambertw(1)
>>> w
(0.56714329040978384+0j)
>>> w * np.exp(w)
(1.0+0j)
任何分支均给出有效的反函数:
>>> w = lambertw(1, k=3)
>>> w
(-2.8535817554090377+17.113535539412148j)
>>> w*np.exp(w)
(1.0000000000000002+1.609823385706477e-15j)
方程求解应用
莱姆伯特 W 函数可用于解决各种类型的方程。这里我们给出两个例子。
首先,该函数可用于解决形如
(x = a + b e^{c x})
对于(x)。我们假设(c)不为零。经过一点代数,方程可写为
(z e^z = -b c e^{a c})
其中(z = c (a - x))。然后可以使用 Lambert W 函数表达(z)。
(z = W(-b c e^{a c}))
给出
(x = a - W(-b c e^{a c})/c)
例如,
>>> a = 3
>>> b = 2
>>> c = -0.5
解(x = a + b e^{c x})的方程是:
>>> x = a - lambertw(-b*c*np.exp(a*c))/c
>>> x
(3.3707498368978794+0j)
验证它是否解决了方程:
>>> a + b*np.exp(c*x)
(3.37074983689788+0j)
Lambert W 函数也可用于找出无限功率塔 (z^{z^{z^{\ldots}}}) 的值:
>>> def tower(z, n):
... if n == 0:
... return z
... return z ** tower(z, n-1)
...
>>> tower(0.5, 100)
0.641185744504986
>>> -lambertw(-np.log(0.5)) / np.log(0.5)
(0.64118574450498589+0j)
scipy.special.wrightomega
scipy.special.wrightomega(z, out=None) = <ufunc 'wrightomega'>
Wright Omega 函数。
定义为解满足
[\omega + \log(\omega) = z]
其中 (\log) 是复对数的主分支。
参数:
z数组类似
评估 Wright Omega 函数的点
out ndarray,可选
函数值的可选输出数组
返回值:
omega标量或者 ndarray
Wright Omega 函数的值
参见
lambertw
Lambert W 函数
注释
0.19.0 版本中新增。
函数也可定义为
[\omega(z) = W_{K(z)}(e^z)]
其中 (K(z) = \lceil (\Im(z) - \pi)/(2\pi) \rceil) 是解缠数,(W) 是 Lambert W 函数。
这里的实现取自[1]。
参考文献
[1]
Lawrence, Corless, and Jeffrey, “Algorithm 917: Complex Double-Precision Evaluation of the Wright (\omega) Function.” ACM Transactions on Mathematical Software, 2012. DOI:10.1145/2168773.2168779.
示例
>>> import numpy as np
>>> from scipy.special import wrightomega, lambertw
>>> wrightomega([-2, -1, 0, 1, 2])
array([0.12002824, 0.27846454, 0.56714329, 1\. , 1.5571456 ])
复数输入:
>>> wrightomega(3 + 5j)
(1.5804428632097158+3.8213626783287937j)
验证 wrightomega(z) 满足 w + log(w) = z:
>>> w = -5 + 4j
>>> wrightomega(w + np.log(w))
(-5+4j)
验证与 lambertw 的联系:
>>> z = 0.5 + 3j
>>> wrightomega(z)
(0.0966015889280649+1.4937828458191993j)
>>> lambertw(np.exp(z))
(0.09660158892806493+1.4937828458191993j)
>>> z = 0.5 + 4j
>>> wrightomega(z)
(-0.3362123489037213+2.282986001579032j)
>>> lambertw(np.exp(z), k=1)
(-0.33621234890372115+2.282986001579032j)
scipy.special.agm
原文:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.agm.html#scipy.special.agm
scipy.special.agm(a, b, out=None) = <ufunc 'agm'>
计算a和b的算术-几何平均值。
从 a_0 = a 和 b_0 = b 开始,并迭代计算:
a_{n+1} = (a_n + b_n)/2
b_{n+1} = sqrt(a_n*b_n)
随着 n 的增加,a_n 和 b_n 趋于相同的极限;它们的共同极限是 agm(a, b)。
参数:
a, barray_like
仅适用于实数值。如果值均为负数,则结果为负数。如果一个值为负,另一个值为正,则返回nan。
outndarray,可选
函数值的可选输出数组
返回:
标量或 ndarray
a和b的算术-几何平均值。
示例
>>> 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]])
scipy.special.bernoulli
scipy.special.bernoulli(n)
伯努利数 B0..Bn(包括)。
参数:
nint
指示要生成伯努利级数中的项数。
返回:
ndarray
伯努利数 [B(0), B(1), ..., B(n)]。
参考文献
[1]
张善杰和金建明,“特殊函数的计算”,约翰·威利和儿子,1996 年。people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html
[2]
“伯努利数”,维基百科,en.wikipedia.org/wiki/Bernoulli_number
示例
>>> import numpy as np
>>> from scipy.special import bernoulli, zeta
>>> bernoulli(4)
array([ 1\. , -0.5 , 0.16666667, 0\. , -0.03333333])
维基百科文章([2])指出了伯努利数与黎曼 zeta 函数的关系,B_n^+ = -n * zeta(1 - n) 对于 n > 0:
>>> n = np.arange(1, 5)
>>> -n * zeta(1 - n)
array([ 0.5 , 0.16666667, -0\. , -0.03333333])
注意,在维基百科文章中使用的符号中,bernoulli 计算的是 B_n^-(即采用 B_1 = -1/2 的约定)。上述给出的关系式是用于 B_n^+ 的,因此 0.5 的符号与 bernoulli(4) 的输出不匹配。
scipy.special.binom
原文:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.binom.html#scipy.special.binom
scipy.special.binom(x, y, out=None) = <ufunc 'binom'>
将二项式系数视为两个实变量的函数。
对于实数参数,二项式系数定义如下:
[\binom{x}{y} = \frac{\Gamma(x + 1)}{\Gamma(y + 1)\Gamma(x - y + 1)} = \frac{1}{(x + 1)\mathrm{B}(x - y + 1, y + 1)}]
其中(\Gamma)是 Gamma 函数(gamma),(\mathrm{B})是 Beta 函数(beta)[1]。
参数:
x, y:array_like
(\binom{x}{y})的实数参数。
out:ndarray,可选
函数值的可选输出数组
返回:
标量或 ndarray
二项式系数的值。
另见:
N 件事物中取 k 件的组合数。
注意事项:
Gamma 函数在非正整数处有极点,并且在实数线上的极点方向决定其趋向于正无穷大或负无穷大。当将(\binom{x}{y})视为两个实变量的函数时,当x为负整数时是未定义的。binom在x为负整数时返回nan。即使当x为负整数且y为整数时,也与通常定义(\binom{n}{k})的约定相反,当其被视为两个整数变量的函数时。
参考文献:
en.wikipedia.org/wiki/Binomial_coefficient
示例:
以下示例说明了binom与函数comb的差异。
>>> from scipy.special import binom, comb
当exact=False且x和y均为正数时,comb在内部调用binom。
>>> x, y = 3, 2
>>> (binom(x, y), comb(x, y), comb(x, y, exact=True))
(3.0, 3.0, 3)
对于较大的值,comb中的exact=True与binom不再一致。
>>> x, y = 43, 23
>>> (binom(x, y), comb(x, y), comb(x, y, exact=True))
(960566918219.9999, 960566918219.9999, 960566918220)
当x为负整数时,binom返回nan,但对于负参数仍然有定义。当x或y为负数或x小于y时,comb返回 0。
>>> x, y = -3, 2
>>> (binom(x, y), comb(x, y), comb(x, y, exact=True))
(nan, 0.0, 0)
>>> x, y = -3.1, 2.2
>>> (binom(x, y), comb(x, y), comb(x, y, exact=True))
(18.714147876804432, 0.0, 0)
>>> x, y = 2.2, 3.1
>>> (binom(x, y), comb(x, y), comb(x, y, exact=True))
(0.037399983365134115, 0.0, 0)
scipy.special.diric
原文:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.diric.html#scipy.special.diric
scipy.special.diric(x, n)
周期性 sinc 函数,也称为 Dirichlet 函数。
Dirichlet 函数的定义如下:
diric(x, n) = sin(x * n/2) / (n * sin(x / 2)),
其中 n 是一个正整数。
参数:
xarray_like
输入数据
nint
定义周期性的整数。
返回:
diricndarray
示例
>>> import numpy as np
>>> from scipy import special
>>> import matplotlib.pyplot as plt
>>> x = np.linspace(-8*np.pi, 8*np.pi, num=201)
>>> plt.figure(figsize=(8, 8));
>>> for idx, n in enumerate([2, 3, 4, 9]):
... plt.subplot(2, 2, idx+1)
... plt.plot(x, special.diric(x, n))
... plt.title('diric, n={}'.format(n))
>>> plt.show()
以下示例演示了 diric 给出矩形脉冲的傅里叶系数的幅度(模去符号和缩放)。
抑制那些实际上为 0 的值的输出:
>>> np.set_printoptions(suppress=True)
使用 k 个 1 创建长度为 m 的信号 x:
>>> m = 8
>>> k = 3
>>> x = np.zeros(m)
>>> x[:k] = 1
使用 FFT 计算 x 的傅里叶变换,并检查系数的幅度:
>>> np.abs(np.fft.fft(x))
array([ 3\. , 2.41421356, 1\. , 0.41421356, 1\. ,
0.41421356, 1\. , 2.41421356])
现在使用 diric 找到相同的值(符号上相同)。我们乘以 k 来考虑 numpy.fft.fft 和 diric 不同的缩放惯例:
>>> theta = np.linspace(0, 2*np.pi, m, endpoint=False)
>>> k * special.diric(theta, k)
array([ 3\. , 2.41421356, 1\. , -0.41421356, -1\. ,
-0.41421356, 1\. , 2.41421356])
scipy.special.euler
原文:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.euler.html#scipy.special.euler
scipy.special.euler(n)
欧拉数 E(0), E(1), …, E(n)。
欧拉数 [1] 也被称为割线数。
因为 euler(n) 返回浮点数值,对于大的 n 并不给出精确值。第一个不精确值是 E(22)。
参数:
n 整数
返回应返回的欧拉数的最高索引。
返回:
ndarray
欧拉数 [E(0), E(1), …, E(n)]。包括所有为零的奇数欧拉数。
参考文献
[1]
序列 A122045, 整数序列在线百科全书, oeis.org/A122045
[2]
张, 善杰 和 金, 建明. “特殊函数的计算”, John Wiley and Sons, 1996. people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html
示例
>>> import numpy as np
>>> from scipy.special import euler
>>> euler(6)
array([ 1., 0., -1., 0., 5., 0., -61.])
>>> euler(13).astype(np.int64)
array([ 1, 0, -1, 0, 5, 0, -61,
0, 1385, 0, -50521, 0, 2702765, 0])
>>> euler(22)[-1] # Exact value of E(22) is -69348874393137901.
-69348874393137976.0
scipy.special.expn
原文链接:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.expn.html#scipy.special.expn
scipy.special.expn(n, x, out=None) = <ufunc 'expn'>
广义指数积分 En。
对于整数 (n \geq 0) 和实数 (x \geq 0),广义指数积分被定义为 [dlmf]
[E_n(x) = x^{n - 1} \int_x^\infty \frac{e^{-t}}{t^n} dt.]
参数:
n 数组类型
非负整数
x 数组类型
实数参数
out ndarray,可选
函数结果的可选输出数组
返回:
标量或者 ndarray
广义指数积分的值
另请参见
exp1
当 (n = 1) 时的特例 (E_n)。
expi
当 (n = 1) 时与 (E_n) 相关。
参考资料
[dlmf]
数学函数数字图书馆,8.19.2 dlmf.nist.gov/8.19#E2
示例
>>> import numpy as np
>>> import scipy.special as sc
其定义域是非负的 n 和 x。
>>> sc.expn(-1, 1.0), sc.expn(1, -1.0)
(nan, nan)
当 (n = 1, 2) 时,在 x = 0 处有极点;对于更大的 (n),它等于 1 / (n - 1)。
>>> sc.expn([0, 1, 2, 3, 4], 0)
array([ inf, inf, 1\. , 0.5 , 0.33333333])
当 (n = 0) 时简化为 exp(-x) / x。
>>> x = np.array([1, 2, 3, 4])
>>> sc.expn(0, x)
array([0.36787944, 0.06766764, 0.01659569, 0.00457891])
>>> np.exp(-x) / x
array([0.36787944, 0.06766764, 0.01659569, 0.00457891])
当 (n = 1) 时简化为 exp1。
>>> sc.expn(1, x)
array([0.21938393, 0.04890051, 0.01304838, 0.00377935])
>>> sc.exp1(x)
array([0.21938393, 0.04890051, 0.01304838, 0.00377935])