scipy.special.psi
原文:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.psi.html#scipy.special.psi
scipy.special.psi(z, out=None) = <ufunc 'psi'>
Digamma 函数。
在z
处评估的伽玛函数的对数导数。
参数:
zarray_like
实数或复数参数。
out ndarray,可选
用于计算psi
值的数组。
返回:
digamma标量或 ndarray
计算出的psi
值。
注意
对于不接近负实轴的大值,使用渐近级数(5.11.2)来计算psi
,参见[1]。对于不接近负实轴的小参数,使用递推关系(5.5.2),直到参数足够大以使用渐近级数。对于接近负实轴的值,首先使用反射公式(5.5.4)参见[1]。注意,psi
在负实轴上有一系列零点,这些零点出现在非正整数极点之间。在这些零点周围,反射公式会由于抵消而导致实现精度下降。然而,第一个正零点和第一个负零点通过预先计算级数展开来单独处理,参见[2],因此函数应在原点周围保持完全准确。
参考文献
[1] (1,2,3)
NIST 数字数学函数库 dlmf.nist.gov/5
[2]
Fredrik Johansson 等人。“mpmath:用于任意精度浮点算术的 Python 库”(版本 0.19)mpmath.org/
示例
>>> from scipy.special import psi
>>> z = 3 + 4j
>>> psi(z)
(1.55035981733341+1.0105022091860445j)
验证 psi(z) = psi(z + 1) - 1/z:
>>> psi(z + 1) - 1/z
(1.55035981733341+1.0105022091860445j)
scipy.special.rgamma
原文:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.rgamma.html#scipy.special.rgamma
scipy.special.rgamma(z, out=None) = <ufunc 'rgamma'>
Gamma 函数的倒数。
定义为(1 / \Gamma(z)),其中(\Gamma)为 Gamma 函数。有关 Gamma 函数的更多信息,请参见gamma
。
参数:
zarray_like
实数或复数输入
outndarray,可选
可选的输出数组用于函数结果
返回:
标量或者 ndarray
函数结果
另请参见
gamma
、gammaln
、loggamma
注意事项
Gamma 函数在非正整数处没有零点,且在非正整数处有简单的极点,因此rgamma
是一个在非正整数处有零点的整函数。详见[dlmf]中的讨论以获取更多详情。
参考文献
[dlmf]
Nist, 数学函数数字化图书馆, dlmf.nist.gov/5.2#i
示例
>>> import scipy.special as sc
它是 Gamma 函数的倒数。
>>> sc.rgamma([1, 2, 3, 4])
array([1\. , 1\. , 0.5 , 0.16666667])
>>> 1 / sc.gamma([1, 2, 3, 4])
array([1\. , 1\. , 0.5 , 0.16666667])
它在非正整数处为零。
>>> sc.rgamma([0, -1, -2, -3])
array([0., 0., 0., 0.])
它在正实轴上迅速地向零下溢。
>>> sc.rgamma([10, 100, 179])
array([2.75573192e-006, 1.07151029e-156, 0.00000000e+000])
scipy.special.polygamma
scipy.special.polygamma(n, x)
Polygamma 函数。
定义为 (\psi^{(n)}(x)),其中 (\psi) 是digamma
函数。详细信息请参见[dlmf]。
参数:
narray_like
digamma
函数的导数阶数;必须是整数
xarray_like
实数值输入
返回:
ndarray
函数结果
参见
digamma
参考
[dlmf]
NIST,数字数学函数库,dlmf.nist.gov/5.15
示例
>>> from scipy import special
>>> x = [2, 3, 25.5]
>>> special.polygamma(1, x)
array([ 0.64493407, 0.39493407, 0.03999467])
>>> special.polygamma(0, x) == special.psi(x)
array([ True, True, True], dtype=bool)
scipy.special.multigammaln
scipy.special.multigammaln(a, d)
返回多变量伽马函数的对数,有时也称为广义伽马函数。
参数:
andarray
为每个 a 的项计算多变量伽马函数。
dint
积分空间的维度。
返回:
resndarray
在给定点 a 处的对数多变量伽马函数的值。
注意事项
对于实数 a 的多变量伽马函数的形式定义是
[\Gamma_d(a) = \int_{A>0} e^{-tr(A)} |A|^{a - (d+1)/2} dA]
条件是 (a > (d-1)/2),且 (A > 0) 是所有正定矩阵集合的维度 d。注意 a 是标量:被积函数是多变量的,但参数不是(该函数在实数集的一个子集上定义)。
可以证明这等于更友好的方程式
[\Gamma_d(a) = \pi^{d(d-1)/4} \prod_{i=1}^{d} \Gamma(a - (i-1)/2).]
参考文献
R. J. Muirhead,《多元统计理论的各个方面》(Wiley Series in probability and mathematical statistics)。
示例
>>> import numpy as np
>>> from scipy.special import multigammaln, gammaln
>>> a = 23.5
>>> d = 10
>>> multigammaln(a, d)
454.1488605074416
验证结果是否与上述方程的对数一致:
>>> d*(d-1)/4*np.log(np.pi) + gammaln(a - 0.5*np.arange(0, d)).sum()
454.1488605074416
scipy.special.digamma
原文:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.digamma.html#scipy.special.digamma
scipy.special.digamma(z, out=None) = <ufunc 'psi'>
Digamma 函数。
伽玛函数的对数导数,在z
处评估。
参数:
z数组型
实部或复数参数。
out ndarray,可选
用于计算psi
值的数组。
返回:
digamma标量或 ndarray
计算出的psi
值。
注意事项
对于大值,而非接近负实轴的情况,使用渐近级数(5.11.2)计算psi
,见[1]。对于小参数,而非接近负实轴的情况,使用递归关系(5.5.2),直至参数足够大可使用渐近级数。对于接近负实轴的值,首先使用反射公式(5.5.4),见[1]。请注意,psi
在负实轴上具有一族零点,这些零点位于非正整数的极点之间。在这些零点周围,反射公式会遭遇抵消问题,导致实现失去精度。然而,正零点和第一个负零点通过预计算使用[2]的级数展开来单独处理,因此该函数应在原点周围保持完全精度。
参考文献
[1] (1,2,3)
NIST 数学函数数字图书馆 dlmf.nist.gov/5
[2]
Fredrik Johansson 及其它。“mpmath: 一种用于任意精度浮点运算的 Python 库”(版本 0.19) mpmath.org/
例子
>>> from scipy.special import psi
>>> z = 3 + 4j
>>> psi(z)
(1.55035981733341+1.0105022091860445j)
验证 psi(z) = psi(z + 1) - 1/z:
>>> psi(z + 1) - 1/z
(1.55035981733341+1.0105022091860445j)
scipy.special.poch
原文:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.poch.html#scipy.special.poch
scipy.special.poch(z, m, out=None) = <ufunc 'poch'>
Pochhammer 符号。
Pochhammer 符号(上升阶乘)定义如下:
[(z)_m = \frac{\Gamma(z + m)}{\Gamma(z)}]
对于正整数 m,它读取
[(z)_m = z (z + 1) … (z + m - 1)]
更多详细信息请参见[dlmf]。
参数:
z, marray_like
实数参数。
outndarray, 可选
函数结果的可选输出数组
返回:
标量或者 ndarray
函数的值。
参考资料
[dlmf]
Nist, 数学函数数字图书馆 dlmf.nist.gov/5.2#iii
示例
>>> import scipy.special as sc
当 m 为 0 时为 1。
>>> sc.poch([1, 2, 3, 4], 0)
array([1., 1., 1., 1.])
当 z 等于 1 时,它缩减为阶乘函数。
>>> sc.poch(1, 5)
120.0
>>> 1 * 2 * 3 * 4 * 5
120
可用 gamma 函数表示。
>>> z, m = 3.7, 2.1
>>> sc.poch(z, m)
20.529581933776953
>>> sc.gamma(z + m) / sc.gamma(z)
20.52958193377696
scipy.special.erf
原文:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.erf.html#scipy.special.erf
scipy.special.erf(z, out=None) = <ufunc 'erf'>
返回复数参数的误差函数。
定义为2/sqrt(pi)*integral(exp(-t**2), t=0..z)
。
参数:
xndarray
输入数组。
outndarray, optional
函数值的可选输出数组
返回:
res标量或 ndarray
在给定点x处的误差函数值。
另见
erfc
, erfinv
, erfcinv
, wofz
, erfcx
, erfi
注释
单位正态分布的累积由Phi(z) = 1/2[1 + erf(z/sqrt(2))]
给出。
参考
[1]
en.wikipedia.org/wiki/Error_function
[2]
Milton Abramowitz 和 Irene A. Stegun,编辑。数学函数手册,包含公式、图表和数学表。纽约:Dover,1972 年。 www.math.sfu.ca/~cbm/aands/page_297.htm
[3]
Steven G. Johnson,Faddeeva W 函数实现。 ab-initio.mit.edu/Faddeeva
示例
>>> import numpy as np
>>> from scipy import special
>>> import matplotlib.pyplot as plt
>>> x = np.linspace(-3, 3)
>>> plt.plot(x, special.erf(x))
>>> plt.xlabel('$x$')
>>> plt.ylabel('$erf(x)$')
>>> plt.show()
scipy.special.erfc
原文链接:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.erfc.html#scipy.special.erfc
scipy.special.erfc(x, out=None) = <ufunc 'erfc'>
补充误差函数,1 - erf(x)
。
参数:
x array_like
实数或复数参数
out ndarray,可选
用于函数结果的可选输出数组
返回:
标量或 ndarray
补充误差函数的值
另请参阅
erf
, erfi
, erfcx
, dawsn
, wofz
参考文献
[1]
Steven G. Johnson,Faddeeva W 函数实现。ab-initio.mit.edu/Faddeeva
示例
>>> import numpy as np
>>> from scipy import special
>>> import matplotlib.pyplot as plt
>>> x = np.linspace(-3, 3)
>>> plt.plot(x, special.erfc(x))
>>> plt.xlabel('$x$')
>>> plt.ylabel('$erfc(x)$')
>>> plt.show()
scipy.special.erfcx
原文链接:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.erfcx.html#scipy.special.erfcx
scipy.special.erfcx(x, out=None) = <ufunc 'erfcx'>
缩放的余补误差函数,exp(x**2) * erfc(x)
。
参数:
xarray_like
实数或复数值的参数
outndarray,可选
函数结果的可选输出数组
返回:
标量或者 ndarray
缩放的余补误差函数的值
参见
erf
,erfc
,erfi
,dawsn
,wofz
注释
版本 0.12.0 中的新功能。
参考文献
[1]
Steven G. Johnson,Faddeeva W 函数实现。ab-initio.mit.edu/Faddeeva
示例
>>> import numpy as np
>>> from scipy import special
>>> import matplotlib.pyplot as plt
>>> x = np.linspace(-3, 3)
>>> plt.plot(x, special.erfcx(x))
>>> plt.xlabel('$x$')
>>> plt.ylabel('$erfcx(x)$')
>>> plt.show()
scipy.special.erfi
原文链接:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.erfi.html#scipy.special.erfi
scipy.special.erfi(z, out=None) = <ufunc 'erfi'>
虚误差函数,-i erf(i z)
。
参数:
zarray_like
实数或复数值参数
outndarray,可选
函数结果的可选输出数组
返回:
标量或者 ndarray
虚误差函数的值
另请参见
注意
新版本 0.12.0 中的内容。
参考文献
[1]
Steven G. Johnson,Faddeeva W 函数实现。ab-initio.mit.edu/Faddeeva
示例
>>> import numpy as np
>>> from scipy import special
>>> import matplotlib.pyplot as plt
>>> x = np.linspace(-3, 3)
>>> plt.plot(x, special.erfi(x))
>>> plt.xlabel('$x$')
>>> plt.ylabel('$erfi(x)$')
>>> plt.show()
scipy.special.erfinv
原文链接:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.erfinv.html#scipy.special.erfinv
scipy.special.erfinv(y, out=None) = <ufunc 'erfinv'>
误差函数的逆函数。
计算误差函数的逆函数。
在复数域中,没有唯一的复数 w 满足 erf(w)=z。这表明真正的逆函数将是多值的。当域限制为实数,-1 < x < 1 时,有一个唯一的实数满足 erf(erfinv(x)) = x。
参数:
y ndarray
评估位置的参数。域:[-1, 1]
out ndarray, 可选
函数值的可选输出数组
返回:
erfinv 标量或 ndarray
y 的 erf 的逆函数,逐元素
参见
复数参数的误差函数
互补误差函数,1 - erf(x)
互补误差函数的逆函数
示例
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from scipy.special import erfinv, erf
>>> erfinv(0.5)
0.4769362762044699
>>> y = np.linspace(-1.0, 1.0, num=9)
>>> x = erfinv(y)
>>> x
array([ -inf, -0.81341985, -0.47693628, -0.22531206, 0\. ,
0.22531206, 0.47693628, 0.81341985, inf])
验证 erf(erfinv(y))
等于 y
。
>>> erf(x)
array([-1\. , -0.75, -0.5 , -0.25, 0\. , 0.25, 0.5 , 0.75, 1\. ])
绘制函数:
>>> y = np.linspace(-1, 1, 200)
>>> fig, ax = plt.subplots()
>>> ax.plot(y, erfinv(y))
>>> ax.grid(True)
>>> ax.set_xlabel('y')
>>> ax.set_title('erfinv(y)')
>>> plt.show()
scipy.special.erfcinv
原文链接:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.erfcinv.html#scipy.special.erfcinv
scipy.special.erfcinv(y, out=None) = <ufunc 'erfcinv'>
补充误差函数的逆函数。
计算补充误差函数的逆函数。
在复数域中,不存在唯一复数 w 满足 erfc(w)=z。这表明真正的逆函数将是多值的。当定义域限制在实数,0 < x < 2 时,存在唯一的实数满足 erfc(erfcinv(x)) = erfcinv(erfc(x))。
它与误差函数的逆相关,通过 erfcinv(1-x) = erfinv(x)
参数:
y ndarray
评估的参数。定义域:[0, 2]
out ndarray,可选
函数值的可选输出数组
返回:
erfcinv 标量或者 ndarray
y 的 erfc 的逆函数,逐元素
参见
复数参数的误差函数
补充误差函数,1 - erf(x)
误差函数的逆函数
示例
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from scipy.special import erfcinv
>>> erfcinv(0.5)
0.4769362762044699
>>> y = np.linspace(0.0, 2.0, num=11)
>>> erfcinv(y)
array([ inf, 0.9061938 , 0.59511608, 0.37080716, 0.17914345,
-0\. , -0.17914345, -0.37080716, -0.59511608, -0.9061938 ,
-inf])
绘制函数:
>>> y = np.linspace(0, 2, 200)
>>> fig, ax = plt.subplots()
>>> ax.plot(y, erfcinv(y))
>>> ax.grid(True)
>>> ax.set_xlabel('y')
>>> ax.set_title('erfcinv(y)')
>>> plt.show()
scipy.special.wofz
原文:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.wofz.html#scipy.special.wofz
scipy.special.wofz(z, out=None) = <ufunc 'wofz'>
Faddeeva 函数
返回复数参数的 Faddeeva 函数的值:
exp(-z**2) * erfc(-i*z)
参数:
z 数组形式
复数参数
out ndarray,可选
可选的输出数组,用于函数结果
返回:
标量或 ndarray
Faddeeva 函数的值
另请参阅
dawsn
,erf
,erfc
,erfcx
,erfi
参考文献
[1]
Steven G. Johnson,Faddeeva W 函数实现。ab-initio.mit.edu/Faddeeva
示例
>>> import numpy as np
>>> from scipy import special
>>> import matplotlib.pyplot as plt
>>> x = np.linspace(-3, 3)
>>> z = special.wofz(x)
>>> plt.plot(x, z.real, label='wofz(x).real')
>>> plt.plot(x, z.imag, label='wofz(x).imag')
>>> plt.xlabel('$x$')
>>> plt.legend(framealpha=1, shadow=True)
>>> plt.grid(alpha=0.25)
>>> plt.show()
scipy.special.dawsn
原文链接:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.dawsn.html#scipy.special.dawsn
scipy.special.dawsn(x, out=None) = <ufunc 'dawsn'>
Dawson 积分。
计算:
exp(-x**2) * integral(exp(t**2), t=0..x).
参数:
xarray_like
函数参数。
输出ndarray,可选
函数值的可选输出数组
返回:
y标量或 ndarray
积分值。
参见
wofz
,erf
,erfc
,erfcx
,erfi
参考文献
[1]
Steven G. Johnson,Faddeeva W 函数实现。ab-initio.mit.edu/Faddeeva
示例
>>> import numpy as np
>>> from scipy import special
>>> import matplotlib.pyplot as plt
>>> x = np.linspace(-15, 15, num=1000)
>>> plt.plot(x, special.dawsn(x))
>>> plt.xlabel('$x$')
>>> plt.ylabel('$dawsn(x)$')
>>> plt.show()
scipy.special.fresnel
原文:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.fresnel.html#scipy.special.fresnel
scipy.special.fresnel(z, out=None) = <ufunc 'fresnel'>
Fresnel 积分
Fresnel 积分被定义为
[\begin{split}S(z) &= \int_0^z \sin(\pi t² /2) dt \ C(z) &= \int_0^z \cos(\pi t² /2) dt.\end{split}]
详细信息请参见[dlmf]。
参数:
z类似数组
实数或复数值的参数
out2 个 ndarray 数组,可选
函数结果的可选输出数组
返回值:
S, C2 个标量或 ndarray 数组
Fresnel 积分的值
参见
fresnel_zeros
Fresnel 积分的零点
参考文献
[dlmf]
美国国家标准与技术研究院数字数学函数库dlmf.nist.gov/7.2#iii
示例
>>> import numpy as np
>>> import scipy.special as sc
当 z 沿着实轴趋向无穷时,S 和 C 收敛于 0.5。
>>> S, C = sc.fresnel([0.1, 1, 10, 100, np.inf])
>>> S
array([0.00052359, 0.43825915, 0.46816998, 0.4968169 , 0.5 ])
>>> C
array([0.09999753, 0.7798934 , 0.49989869, 0.4999999 , 0.5 ])
它们与误差函数erf
相关。
>>> z = np.array([1, 2, 3, 4])
>>> zeta = 0.5 * np.sqrt(np.pi) * (1 - 1j) * z
>>> S, C = sc.fresnel(z)
>>> C + 1j*S
array([0.7798934 +0.43825915j, 0.48825341+0.34341568j,
0.60572079+0.496313j , 0.49842603+0.42051575j])
>>> 0.5 * (1 + 1j) * sc.erf(zeta)
array([0.7798934 +0.43825915j, 0.48825341+0.34341568j,
0.60572079+0.496313j , 0.49842603+0.42051575j])
scipy.special.fresnel_zeros
scipy.special.fresnel_zeros(nt)
计算正弦和余弦 Fresnel 积分 S(z) 和 C(z) 的 nt 个复数零点。
Parameters:
ntint
需要计算的零点数量
Returns:
zeros_sine: ndarray
正弦 Fresnel 积分的零点
zeros_cosinendarray
余弦 Fresnel 积分的零点
References
[1]
张善杰和金建明,“特殊函数的计算”,John Wiley and Sons,1996 年。people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html
scipy.special.modfresnelp
Original text:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.modfresnelp.html#scipy.special.modfresnelp
scipy.special.modfresnelp(x, out=None) = <ufunc 'modfresnelp'>
修改的 Fresnel 正积分
参数:
x类似数组
函数参数
outndarray 元组,可选
可选的输出数组,用于函数结果
返回:
fp标量或数组
积分 F_+(x)
: integral(exp(1j*t*t), t=x..inf)
kp标量或数组
积分 K_+(x)
: 1/sqrt(pi)*exp(-1j*(x*x+pi/4))*fp
另见
modfresnelm
scipy.special.modfresnelm
scipy.special.modfresnelm(x, out=None) = <ufunc 'modfresnelm'>
修改的 Fresnel 负积分
参数:
x类似数组
函数参数
outndarray 的元组,可选
函数结果的可选输出数组
返回:
fm标量或者 ndarray
积分 F_-(x)
: integral(exp(-1j*t*t), t=x..inf)
km标量或者 ndarray
积分 K_-(x)
: 1/sqrt(pi)*exp(1j*(x*x+pi/4))*fp
参见
scipy.special.voigt_profile
scipy.special.voigt_profile(x, sigma, gamma, out=None) = <ufunc 'voigt_profile'>
Voigt 分布。
Voigt 分布是一个由标准差为 sigma
的一维正态分布和半高宽为 gamma
的一维柯西分布卷积而成的分布。
如果 sigma = 0
,则返回柯西分布的概率密度函数。相反,如果 gamma = 0
,则返回正态分布的概率密度函数。如果 sigma = gamma = 0
,对于 x = 0
返回值为 Inf
,对于其他所有 x
返回值为 0
。
参数:
xarray_like
实数参数
sigmaarray_like
正态分布部分的标准差
gammaarray_like
柯西分布部分的半高宽
outndarray, 可选参数
可选输出数组以存储函数值
返回:
标量或 ndarray
给定参数的 Voigt 分布
参见
wofz
Faddeeva 函数
注意事项
可以用 Faddeeva 函数来表达
[V(x; \sigma, \gamma) = \frac{Re[w(z)]}{\sigma\sqrt{2\pi}},][z = \frac{x + i\gamma}{\sqrt{2}\sigma}]
其中 (w(z)) 是 Faddeeva 函数。
参考资料
[1]
[zh.wikipedia.org/wiki/Voigt 分布
](https://zh.wikipedia.org/wiki/Voigt 分布)
示例
计算 sigma=1
和 gamma=1
时在点 2 的函数值。
>>> from scipy.special import voigt_profile
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> voigt_profile(2, 1., 1.)
0.09071519942627544
通过提供 NumPy 数组 x 来计算几个点的函数值。
>>> values = np.array([-2., 0., 5])
>>> voigt_profile(values, 1., 1.)
array([0.0907152 , 0.20870928, 0.01388492])
为不同的参数集绘制函数图像。
>>> fig, ax = plt.subplots(figsize=(8, 8))
>>> x = np.linspace(-10, 10, 500)
>>> parameters_list = [(1.5, 0., "solid"), (1.3, 0.5, "dashed"),
... (0., 1.8, "dotted"), (1., 1., "dashdot")]
>>> for params in parameters_list:
... sigma, gamma, linestyle = params
... voigt = voigt_profile(x, sigma, gamma)
... ax.plot(x, voigt, label=rf"$\sigma={sigma},\, \gamma={gamma}$",
... ls=linestyle)
>>> ax.legend()
>>> plt.show()
可视化验证 Voigt 分布确实是正态分布和柯西分布的卷积。
>>> from scipy.signal import convolve
>>> x, dx = np.linspace(-10, 10, 500, retstep=True)
>>> def gaussian(x, sigma):
... return np.exp(-0.5 * x**2/sigma**2)/(sigma * np.sqrt(2*np.pi))
>>> def cauchy(x, gamma):
... return gamma/(np.pi * (np.square(x)+gamma**2))
>>> sigma = 2
>>> gamma = 1
>>> gauss_profile = gaussian(x, sigma)
>>> cauchy_profile = cauchy(x, gamma)
>>> convolved = dx * convolve(cauchy_profile, gauss_profile, mode="same")
>>> voigt = voigt_profile(x, sigma, gamma)
>>> fig, ax = plt.subplots(figsize=(8, 8))
>>> ax.plot(x, gauss_profile, label="Gauss: $G$", c='b')
>>> ax.plot(x, cauchy_profile, label="Cauchy: $C$", c='y', ls="dashed")
>>> xx = 0.5*(x[1:] + x[:-1]) # midpoints
>>> ax.plot(xx, convolved[1:], label="Convolution: $G * C$", ls='dashdot',
... c='k')
>>> ax.plot(x, voigt, label="Voigt", ls='dotted', c='r')
>>> ax.legend()
>>> plt.show()
scipy.special.erf_zeros
scipy.special.erf_zeros(nt)
在第一象限按绝对值排序,计算第一个 nt 个零点。
可通过使用 erf(-z) = erf(z) 和 erf(conj(z)) = conj(erf(z)) 的对称性来获取其他象限的零点。
参数:
ntint
要计算的零点数量
返回:
erf 的零点位置 ndarray(复数)
计算 erf(z) 的零点的复数值
参考文献
[1]
Zhang, Shanjie 和 Jin, Jianming。“特殊函数的计算”,John Wiley and Sons,1996 年。people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html
示例
>>> from scipy import special
>>> special.erf_zeros(1)
array([1.45061616+1.880943j])
检查 erf 对于 erf_zeros 返回的值是否(接近)为零。
>>> special.erf(special.erf_zeros(1))
array([4.95159469e-14-1.16407394e-16j])
scipy.special.fresnelc_zeros
scipy.special.fresnelc_zeros(nt)
计算余弦 Fresnel 积分 C(z) 的 nt 个复零点。
参数:
ntint
要计算的零点数量
返回:
fresnelc_zeros:ndarray
余弦 Fresnel 积分的零点
参考文献
[1]
张善杰和金建明。“特殊函数的计算”,John Wiley and Sons,1996。people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html
scipy.special.fresnels_zeros
scipy.special.fresnels_zeros(nt)
计算正弦弗雷内尔积分 S(z) 的 nt 个复零点。
参数:
ntint
要计算的零点数
返回:
fresnels_zeros: ndarray
正弦弗雷内尔积分的零点
参考文献
[1]
张善杰和金建明。“特殊函数的计算”,约翰·威利和儿子,1996 年。people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html
scipy.special.lpmv
原文:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.lpmv.html#scipy.special.lpmv
scipy.special.lpmv(m, v, x, out=None) = <ufunc 'lpmv'>
整数阶及实数次数的关联勒让德函数。
定义为
[P_v^m = (-1)^m (1 - x²)^{m/2} \frac{dm}{dxm} P_v(x)]
其中
[P_v = \sum_{k = 0}^\infty \frac{(-v)_k (v + 1)_k}{(k!)²} \left(\frac{1 - x}{2}\right)^k]
是第一类勒讪德函数。这里((\cdot)_k)是 Pochhammer 符号;参见poch
。
参数:
marray_like
阶数(整数或浮点)。如果传入浮点数而不是整数,则函数返回 NaN。
varray_like
次数(浮点)。
xarray_like
参数(浮点)。必须满足|x| <= 1
。
outndarray,可选
作为函数结果的可选输出数组
返回:
pmv标量或数组
关联勒让德函数的值。
亦参见
lpmn
计算所有阶数0, ..., m
和次数0, ..., n
的关联勒让德函数。
clpmn
计算复参数的关联勒让德函数。
注意事项
请注意,此实现包含 Condon-Shortley 相位。
参考文献
[1]
张津,“特殊函数的计算”,约翰·威利和儿子出版公司,1996 年。
scipy.special.sph_harm
scipy.special.sph_harm(m, n, theta, phi, out=None) = <ufunc 'sph_harm'>
计算球谐函数。
球谐函数定义如下:
[Y^m_n(\theta,\phi) = \sqrt{\frac{2n+1}{4\pi} \frac{(n-m)!}{(n+m)!}} e^{i m \theta} P^m_n(\cos(\phi))]
其中 (P_n^m) 是相关的 Legendre 函数;详见 lpmv
。
参数:
marray_like
谐波的阶数(整数);必须满足 |m| <= n
。
narray_like
谐波的度数(整数);必须满足 n >= 0
。在球谐函数的描述中,通常用 l
(小写 L)表示。
thetaarray_like
方位角(经度)坐标;必须在 [0, 2*pi]
范围内。
phiarray_like
极坐标(极角);必须在 [0, pi]
范围内。
outndarray, optional
函数值的可选输出数组
返回:
y_mn复数标量或 ndarray
谐波 (Y^m_n) 在 theta
和 phi
处的采样。
Notes
对于输入参数 theta
和 phi
的含义有不同的约定。在 SciPy 中,theta
是方位角,phi
是极角。通常会看到相反的约定,即 theta
是极角,phi
是方位角。
注意,SciPy 的球谐函数包括 Condon-Shortley 相位 [2],因为它是 lpmv
的一部分。
根据 SciPy 的惯例,前几个球谐函数是
[\begin{split}Y_0⁰(\theta, \phi) &= \frac{1}{2} \sqrt{\frac{1}{\pi}} \ Y_1^{-1}(\theta, \phi) &= \frac{1}{2} \sqrt{\frac{3}{2\pi}} e^{-i\theta} \sin(\phi) \ Y_1⁰(\theta, \phi) &= \frac{1}{2} \sqrt{\frac{3}{\pi}} \cos(\phi) \ Y_1¹(\theta, \phi) &= -\frac{1}{2} \sqrt{\frac{3}{2\pi}} e^{i\theta} \sin(\phi).\end{split}]
References
[1]
数字数学函数库,14.30。dlmf.nist.gov/14.30
[2]
en.wikipedia.org/wiki/Spherical_harmonics#Condon.E2.80.93Shortley_phase
scipy.special.clpmn
原文链接:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.clpmn.html#scipy.special.clpmn
scipy.special.clpmn(m, n, z, type=3)
复变量的第一类关联 Legendre 函数。
计算阶数为 m 和阶数为 n 的第一类关联 Legendre 函数 Pmn(z)
= (P_n^m(z)),及其导数 Pmn'(z)
。返回两个大小为 (m+1, n+1)
的数组,包含所有阶数从 0..m
和阶数从 0..n
的 Pmn(z)
和 Pmn'(z)
。
参数:
mint
|m| <= n
;Legendre 函数的阶数。
nint
其中 n >= 0
;Legendre 函数的阶数。通常在相关的 Legendre 函数描述中称为 l
(小写字母 L)。
zfloat 或复数
输入值。
typeint,可选
取值为 2 或 3。2:在实轴上的截断条件为|x| > 1
。3:在实轴上的截断条件为-1 < x < 1
(默认值)。
返回:
Pmn_z(m+1, n+1) 数组
所有阶数 0..m
和阶数 0..n
的数值。
Pmn_d_z(m+1, n+1) 数组
所有阶数 0..m
和阶数 0..n
的导数。
参见
lpmn
实数 z
的第一类关联 Legendre 函数
注意
默认情况下,即 type=3
,根据[1]中的相位约定选择。截断位于区间(-1, 1)。一般从上方或下方逼近截断会得到与 Ferrer 第一类函数相关的相位因子(参考lpmn
)。
对于 type=2
,选择截断在 |x| > 1
。在复平面上的实值逼近区间(-1, 1)给出 Ferrer 第一类函数。
参考文献
[1]
Zhang, Shanjie 和 Jin, Jianming。《特殊函数的计算》,John Wiley 和 Sons,1996 年。people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html
[2]
NIST 数学函数数字图书馆 dlmf.nist.gov/14.21
scipy.special.lpn
原文链接:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.lpn.html#scipy.special.lpn
scipy.special.lpn(n, z)
第一类 Legendre 函数。
计算第一类 Legendre 函数(多项式)Pn(z)及其所有次数从 0 到 n(包括)的导数。
参见多项式类 special.legendre。
参考资料
[1]
张善杰、金建明著,《特殊函数计算》,John Wiley and Sons,1996 年。people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html
scipy.special.lqn
原文:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.lqn.html#scipy.special.lqn
scipy.special.lqn(n, z)
第二类 Legendre 函数。
计算第二类 Legendre 函数 Qn(z)及其从 0 到 n(包括)的所有阶数的导数序列。
参考资料
[1]
张善杰,金建明。“特殊函数的计算”,John Wiley and Sons,1996。people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html
scipy.special.lpmn
原文链接:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.lpmn.html#scipy.special.lpmn
scipy.special.lpmn(m, n, z)
相关勒让德函数的序列,第一类。
计算阶数为 m 和角度为 n 的第一类相关勒让德函数,Pmn(z)
= (P_n^m(z)),及其导数,Pmn'(z)
。返回大小为(m+1, n+1)
的两个数组,包含0..m
阶和0..n
角度的Pmn(z)
和Pmn'(z)
。
此函数采用实数参数 z
。对于复数参数 z
,请使用 clpmn。
参数:
mint
|m| <= n
; 勒让德函数的阶数。
nint
其中 n >= 0
; 勒让德函数的阶数。在描述相关勒让德函数时通常称为 l
(小写 L)。
zfloat
输入值。
返回:
Pmn_z(m+1, n+1) 数组
所有阶数 0…m 和角度 0…n 的值
Pmn_d_z(m+1, n+1) 数组
所有阶数 0…m 和角度 0…n 的导数
另见
clpmn
复数 z 的第一类相关勒让德函数
注
在区间(-1, 1)内返回费雷尔函数的第一类。用于区间(1, inf)和(-inf, -1)的相位约定使得结果始终是实数。
参考
[1]
张善杰和金建明。“特殊函数的计算”,约翰·威利和儿子,1996 年。people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html
[2]
NIST 数字数学函数库 dlmf.nist.gov/14.3
scipy.special.lqmn
原文:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.lqmn.html#scipy.special.lqmn
scipy.special.lqmn(m, n, z)
第二类相关勒让德函数序列。
计算阶数为 m 和次数为 n 的第二类相关勒让德函数 Qmn(z)
= (Q_n^m(z)),及其导数 Qmn'(z)
。返回大小为 (m+1, n+1)
的两个数组,包含所有阶数从 0..m
和次数从 0..n
的 Qmn(z)
和 Qmn'(z)
。
参数:
m整数
|m| <= n
;勒让德函数的阶数。
n整数
其中 n >= 0
;Legendre 函数的次数。在相关勒让德函数的描述中通常称为 l
(小写 L)
z复数
输入值。
返回值:
Qmn_z(m+1, n+1) 数组
所有阶数 0…m 和次数 0…n 的值
Qmn_d_z(m+1, n+1) 数组
所有阶数 0…m 和次数 0…n 的导数
参考文献
[1]
张善杰、金建明著。“特殊函数的计算”,John Wiley and Sons,1996。people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html
scipy.special.ellip_harm
scipy.special.ellip_harm(h2, k2, n, p, s, signm=1, signn=1)
椭球谐波函数 E^p_n(l)
这些也被称为第一类 Lame 函数,是 Lame 方程的解:
[(s² - h²)(s² - k²)E’‘(s) + s(2s² - h² - k²)E’(s) + (a - q s²)E(s) = 0]
其中(q = (n+1)n),(a)是对应解的特征值(不返回)。
参数:
h2float
h**2
k2float
k**2
应大于h**2
n整数
度
s浮点数
坐标
p整数
顺序,可在[1,2n+1]范围内变化
signm{1, -1},可选
函数前缀的符号。可为+/-1。详见注释。
signn{1, -1},可选
函数前缀的符号。可为+/-1。详见注释。
返回:
E浮点数
谐波(E^p_n(s))
请参见
ellip_harm_2
,ellip_normal
注释
椭球函数的几何解释详见[2],[3],[4]。signm和signn参数根据它们的类型控制函数的前缀符号:
K : +1
L : signm
M : signn
N : signm*signn
版本 0.15.0 的新功能。
参考文献
[1]
数字数学函数库 29.12 dlmf.nist.gov/29.12
[2]
Bardhan and Knepley,《计算科学与重发现:椭球谐波的开源实现用于潜在理论问题》,Comput. Sci. Disc. 5, 014006 (2012) DOI:10.1088/1749-4699/5/1/014006。
[3]
David J.and Dechambre P,《计算小型太阳系天体的椭球引力场谐波》,第 30-36 页,2000 年
[4]
George Dassios,《椭球谐波:理论与应用》,第 418 页,2012 年
示例
>>> from scipy.special import ellip_harm
>>> w = ellip_harm(5,8,1,1,2.5)
>>> w
2.5
检查这些函数确实是 Lame 方程的解:
>>> import numpy as np
>>> from scipy.interpolate import UnivariateSpline
>>> def eigenvalue(f, df, ddf):
... r = (((s**2 - h**2) * (s**2 - k**2) * ddf
... + s * (2*s**2 - h**2 - k**2) * df
... - n * (n + 1)*s**2*f) / f)
... return -r.mean(), r.std()
>>> s = np.linspace(0.1, 10, 200)
>>> k, h, n, p = 8.0, 2.2, 3, 2
>>> E = ellip_harm(h**2, k**2, n, p, s)
>>> E_spl = UnivariateSpline(s, E)
>>> a, a_err = eigenvalue(E_spl(s), E_spl(s,1), E_spl(s,2))
>>> a, a_err
(583.44366156701483, 6.4580890640310646e-11)
scipy.special.ellip_harm_2
scipy.special.ellip_harm_2(h2, k2, n, p, s)
椭球谐函数 (F^p_n(l))
这些也被称为第二类拉梅函数,是拉梅方程的解:
[(s² - h²)(s² - k²)F’‘(s) + s(2s² - h² - k²)F’(s) + (a - q s²)F(s) = 0]
其中 (q = (n+1)n) 和 (a) 是与解对应的特征值(不返回)。
参数:
h2float
h**2
k2float
k**2
;应大于 h**2
nint
度数。
pint
顺序,可以在 [1,2n+1] 范围内变化。
sfloat
坐标
返回:
Ffloat
谐波 (F^p_n(s))
参见
注意
第二类拉梅函数与第一类函数相关联:
[F^p_n(s)=(2n + 1)Ep_n(s)\int_{0}{1/s} \frac{du}{(E^p_n(1/u))²\sqrt{(1-u²k²)(1-u²h²)}}]
新版本 0.15.0 中新增。
例子
>>> from scipy.special import ellip_harm_2
>>> w = ellip_harm_2(5,8,2,1,10)
>>> w
0.00108056853382
scipy.special.ellip_normal
scipy.special.ellip_normal(h2, k2, n, p)
椭球谐波规范化常数 (\gamma^p_n)
规范化常数被定义为
[\gammap_n=8\int_{0}{h}dx\int_{h}^{k}dy \frac{(y²-x²)(Ep_n(y)Ep_n(x))²}{\sqrt((k²-y²)(y²-h²)(h²-x²)(k²-x²)}]
参数:
h2 浮点数。
h**2
。
k2 浮点数。
k**2
;应该大于h**2
。
n 整数。
度数。
p 整数。
顺序可以在[1,2n+1]范围内变化。
返回:
gamma 浮点数。
规范化常数 (\gamma^p_n)。
另请参阅:
ellip_harm
,ellip_harm_2
。
注意事项。
新版本为 0.15.0。
示例
>>> from scipy.special import ellip_normal
>>> w = ellip_normal(5,8,3,7)
>>> w
1723.38796997
scipy.special.assoc_laguerre
scipy.special.assoc_laguerre(x, n, k=0.0)
计算广义(关联的)Laguerre 多项式,其次数为 n,阶数为 k。
多项式 (L^{(k)}_n(x)) 在 0, inf)
区间上是正交的,权重函数为 exp(-x) * x**k
,其中 k > -1
。
参数:
xfloat 或 ndarray
Laguerre 多项式的计算点
nint
Laguerre 多项式的次数
kint
Laguerre 多项式的阶数
返回值:
assoc_laguerre: float 或 ndarray
相关的 Laguerre 多项式值
注释
[assoc_laguerre
是 eval_genlaguerre
的一个简单封装,参数顺序为逆序 (x, n, k=0.0) --> (n, k, x)
。
scipy.special.eval_legendre
scipy.special.eval_legendre(n, x, out=None) = <ufunc 'eval_legendre'>
在某一点评估 Legendre 多项式。
可以通过 Gauss 超几何函数({}_2F_1)定义 Legendre 多项式为
[P_n(x) = {}_2F_1(-n, n + 1; 1; (1 - x)/2).]
当(n)是整数时,结果是一个阶数为(n)的多项式。详见[AS]中的 22.5.49 节。
参数:
narray_like
多项式的次数。如果不是整数,则结果通过与 Gauss 超几何函数的关系确定。
xarray_like
评估 Legendre 多项式的点
outndarray,可选
可选输出数组的函数值
返回:
Pscalar 或 ndarray
Legendre 多项式的值
另请参阅
roots_legendre
Legendre 多项式的根和积分权重
legendre
Legendre 多项式对象
hyp2f1
Gauss 超几何函数
numpy.polynomial.legendre.Legendre
Legendre 级数
参考文献
[AS]
Milton Abramowitz 和 Irene A. Stegun,eds. Handbook of Mathematical Functions with Formulas, Graphs, and Mathematical Tables. New York: Dover, 1972.
示例
>>> import numpy as np
>>> from scipy.special import eval_legendre
在 x = 0 处评估零阶 Legendre 多项式
>>> eval_legendre(0, 0)
1.0
在-1 到 1 之间评估一阶 Legendre 多项式
>>> X = np.linspace(-1, 1, 5) # Domain of Legendre polynomials
>>> eval_legendre(1, X)
array([-1\. , -0.5, 0\. , 0.5, 1\. ])
评估阶数为 0 至 4 的 Legendre 多项式在 x = 0 处
>>> N = range(0, 5)
>>> eval_legendre(N, 0)
array([ 1\. , 0\. , -0.5 , 0\. , 0.375])
绘制阶数为 0 至 4 的 Legendre 多项式
>>> X = np.linspace(-1, 1)
>>> import matplotlib.pyplot as plt
>>> for n in range(0, 5):
... y = eval_legendre(n, X)
... plt.plot(X, y, label=r'$P_{}(x)$'.format(n))
>>> plt.title("Legendre Polynomials")
>>> plt.xlabel("x")
>>> plt.ylabel(r'$P_n(x)$')
>>> plt.legend(loc='lower right')
>>> plt.show()
ipy.special.eval_legendre`](https://docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.eval_legendre.html#scipy.special.eval_legendre)
scipy.special.eval_legendre(n, x, out=None) = <ufunc 'eval_legendre'>
在某一点评估 Legendre 多项式。
可以通过 Gauss 超几何函数({}_2F_1)定义 Legendre 多项式为
[P_n(x) = {}_2F_1(-n, n + 1; 1; (1 - x)/2).]
当(n)是整数时,结果是一个阶数为(n)的多项式。详见[AS]中的 22.5.49 节。
参数:
narray_like
多项式的次数。如果不是整数,则结果通过与 Gauss 超几何函数的关系确定。
xarray_like
评估 Legendre 多项式的点
outndarray,可选
可选输出数组的函数值
返回:
Pscalar 或 ndarray
Legendre 多项式的值
另请参阅
roots_legendre
Legendre 多项式的根和积分权重
legendre
Legendre 多项式对象
hyp2f1
Gauss 超几何函数
numpy.polynomial.legendre.Legendre
Legendre 级数
参考文献
[AS]
Milton Abramowitz 和 Irene A. Stegun,eds. Handbook of Mathematical Functions with Formulas, Graphs, and Mathematical Tables. New York: Dover, 1972.
示例
>>> import numpy as np
>>> from scipy.special import eval_legendre
在 x = 0 处评估零阶 Legendre 多项式
>>> eval_legendre(0, 0)
1.0
在-1 到 1 之间评估一阶 Legendre 多项式
>>> X = np.linspace(-1, 1, 5) # Domain of Legendre polynomials
>>> eval_legendre(1, X)
array([-1\. , -0.5, 0\. , 0.5, 1\. ])
评估阶数为 0 至 4 的 Legendre 多项式在 x = 0 处
>>> N = range(0, 5)
>>> eval_legendre(N, 0)
array([ 1\. , 0\. , -0.5 , 0\. , 0.375])
绘制阶数为 0 至 4 的 Legendre 多项式
>>> X = np.linspace(-1, 1)
>>> import matplotlib.pyplot as plt
>>> for n in range(0, 5):
... y = eval_legendre(n, X)
... plt.plot(X, y, label=r'$P_{}(x)$'.format(n))
>>> plt.title("Legendre Polynomials")
>>> plt.xlabel("x")
>>> plt.ylabel(r'$P_n(x)$')
>>> plt.legend(loc='lower right')
>>> plt.show()
[外链图片转存中…(img-1hoyNhCB-1719634377515)]