Mathematica 中的复杂误差函数 [英] Complex Error Function in Mathematica
问题描述
复杂误差函数 w(z) 定义为 e^(-x^2) erfc(-ix)
.使用如上定义的 w(z) 的问题在于,对于较大的 x,erfc 往往会爆炸(由指数趋于 0 补充,因此一切都保持较小),因此 Mathematica 恢复到任意精度计算,这使生活变得非常缓慢.该函数用于实现 voigt 轮廓 - 一种常用于光谱学和其他相关领域的线形.现在我正在恢复计算 lineshape 一次并使用插值来加快速度,但这并不能让我轻松更改 lineshape 的参数(或适合它们).
The complex error function w(z) is defined as e^(-x^2) erfc(-ix)
. The problem with using w(z) as defined above is that the erfc tends to explode out for larger x (complemented by the exponential going to 0 so everything stays small), so that Mathematica reverts to arbitrary precision calculations that make life VERY slow. The function is used in implementing the voigt profile - a line shape commonly used in spectroscopy and other related areas. Right now I'm reverting to calculating the lineshape once and using an interpolation to speed things up, however this doesn't let me alter the parameters of the lineshape (or fit to them) easily.
scipy 将 w(z) 实现为 scipy.special.wofz
,并且我想知道 Mathematica 中是否有等价物.
scipy has a nice and fast implementation of w(z) as scipy.special.wofz
, and I was wondering if there is an equivalent in Mathematica.
推荐答案
复杂误差函数可以写成 Hermite多项式"H_{-1}(x)
:>
The complex error function can be written in terms of the Hermite "polynomial" H_{-1}(x)
:
In[1]:= FullSimplify[2 HermiteH[-1,I x] == Sqrt[Pi] Exp[-x^2] Erfc[I x]]
Out[1]= True
并且评估不会遭受那么多的下溢和上溢
And the evaluation does not suffer as many underflows and overflows
In[68]:= 2 HermiteH[-1, I x] /. x -> 100000.
Out[68]= 6.12323*10^-22 - 0.00001 I
In[69]:= Sqrt[Pi] E^-x^2 Erfc[I x] /. x -> 100000.
During evaluation of In[69]:= General::unfl: Underflow occurred in computation. >>
During evaluation of In[69]:= General::ovfl: Overflow occurred in computation. >>
Out[69]= Indeterminate
也就是说,一些快速测试表明 Hermite 函数的评估速度比指数和误差函数的乘积慢...
That said, some quick tests show that the evaluation speed of the Hermite function to be slower than that of the product of the exponential and error function...
这篇关于Mathematica 中的复杂误差函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!