当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


Python SciPy special.voigt_profile用法及代码示例

本文简要介绍 python 语言中 scipy.special.voigt_profile 的用法。

用法:

scipy.special.voigt_profile(x, sigma, gamma, out=None) = <ufunc 'voigt_profile'>#

沃伊特简介。

Voigt 分布是具有标准差 sigma 的一维正态分布和 half-width 处的一维柯西分布 (half-maximum gamma ) 的卷积。

如果 sigma = 0 ,则返回柯西分布的 PDF。相反,如果 gamma = 0 ,则返回正态分布的 PDF。如果 sigma = gamma = 0 ,则 x = 0 的返回值为 Inf ,所有其他 x 的返回值为 0

参数

x array_like

真正的参数

sigma array_like

正态分布部分的标准差

gamma array_like

柯西分布部分的half-maximum处的half-width

out ndarray,可选

函数值的可选输出数组

返回

标量或 ndarray

给定参数处的 Voigt 剖面

注意

可以用 Faddeeva 函数来表示

其中 是 Faddeeva 函数。

参考

例子

计算 sigma=1gamma=1 在点 2 处的函数。

>>> from scipy.special import voigt_profile
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> voigt_profile(2, 1., 1.)
0.09071519942627544

通过为 x 提供 NumPy 数组来计算多个点的函数。

>>> 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()
scipy-special-voigt_profile-1_00_00.png

目视验证 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-voigt_profile-1_01_00.png

相关用法


注:本文由纯净天空筛选整理自scipy.org大神的英文原创作品 scipy.special.voigt_profile。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。