當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。