慢速收敛积分的数值积分
我基本上对这种类型的数值积分有一个问题:
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import quad
# Parameter
T = 94
Eps_inf = 3.05
Eps_s = 19.184544603857724
tau_0 = 1.27*10**-16
tau_CD = 0.34580390675331274
gamma = 0.49
C_pek = 1/Eps_inf - 1/Eps_s
hbar = 6.582119569*10**-16
# Functions
def func(w):
return -4 * 1/(np.pi * C_pek) * Eps(w).imag/abs(Eps(w))**2
def Eps(w):
return Eps_inf + (Eps_s - Eps_inf)/(1 + (1j * w * tau_CD))**gamma
w = np.logspace(-9,80,100000)
y = func(w)
IntegrandS = quad(lambda w: func(w),0,np.inf,limit=100000)[0]
print(f'quadResult: {IntegrandS}')
这给了我警告:积分可能是发散的,或者缓慢收敛的。
如果我输入积分的上限只是一个像1e15
这样的大数字,它会给我一个结果,但该结果永远不会收敛到越来越高的积分限制。
无论如何,有没有办法处理这个函数,以便四元函数(或任何其他集成方法,我也尝试过 scipys trapz,给我同样的问题)可以处理这个函数?
谢谢!
I basically have a problem with numerical integrations of this type:
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import quad
# Parameter
T = 94
Eps_inf = 3.05
Eps_s = 19.184544603857724
tau_0 = 1.27*10**-16
tau_CD = 0.34580390675331274
gamma = 0.49
C_pek = 1/Eps_inf - 1/Eps_s
hbar = 6.582119569*10**-16
# Functions
def func(w):
return -4 * 1/(np.pi * C_pek) * Eps(w).imag/abs(Eps(w))**2
def Eps(w):
return Eps_inf + (Eps_s - Eps_inf)/(1 + (1j * w * tau_CD))**gamma
w = np.logspace(-9,80,100000)
y = func(w)
IntegrandS = quad(lambda w: func(w),0,np.inf,limit=100000)[0]
print(f'quadResult: {IntegrandS}')
This gives me the warning: The integral is probably divergent, or slowly convergent.
And the function is indeed slowly converging:
If I put in the upper limit of the integration just a big numer like 1e15
it gives me a result but that result will never converge for higher and higher integration limits.
Is there anyway to treat this function, so that the quad function (or any other integration method, i also tried scipys trapz, giving me the same problem) can deal with this function?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
积分是发散的。这可以通过将
func(w)
的渐近行为视为w
来解释→ 无穷大。
func(w)
依赖于w
的部分是商Eps(w).imag/abs(Eps(w))**2.
当
w
→ Infinity 时,Eps(w)
的实部接近Eps_inf
,虚部趋于 0,因此w
→ ∞,abs(Eps(w))**2
→Eps_inf**2
。即,分母接近正常数。因此,该商的重要部分是分子,Eps(w).imag
。当
w
→ ∞时,Eps(w).imag
收敛到0,但这并不意味着func(w)
的积分会收敛。为了收敛,Eps(w).imag
必须“足够快”收敛到 0。当w
→ ∞ 时,Eps(w).imag
的行为类似于D * w**-gamma
,其中D
> 是一个独立于w
的常量。从x0
到 Infini(对于某些x0
> 0)的x**p
形式的积分仅当 p <; 时才收敛。 -1。根据您的函数,该幂为-gamma
,即 -0.49。所以你的函数衰减太慢,积分无法收敛。您可以检查一下,如果将
gamma
更改为大于 1 的值,quad
会收敛。例如,当 gamma 为 1 时,积分发散。在这种情况下,这里有两次使用
quad
的尝试。当
gamma
< 1,quad
(正确地)报告积分可能发散。The integral is divergent. This can be explained by looking at the asymptotic behavior of
func(w)
asw
→ ∞.
The part of
func(w)
that depends onw
is the quotientEps(w).imag/abs(Eps(w))**2
.As
w
→ ∞, the real part ofEps(w)
approachesEps_inf
and the imaginary part goes to 0, so asw
→ ∞,abs(Eps(w))**2
→Eps_inf**2
. That is, the denominator approaches a positive constant. So the important part of that quotient is the numerator,Eps(w).imag
.As
w
→ ∞,Eps(w).imag
converges to 0, but that does not mean the integral offunc(w)
will converge. For convergence,Eps(w).imag
must converge to 0 "fast enough". Asw
→ ∞,Eps(w).imag
behaves likeD * w**-gamma
, whereD
is a constant that is independent ofw
. An integral of the formx**p
fromx0
to ∞ (for somex0
> 0) is convergent only when p < -1. With your function, that power is-gamma
, which is -0.49. So your function decays too slowly for the integral to converge.You can check that if you change
gamma
to a value greater than 1,quad
converges. E.g.The integral is divergent when gamma is 1. Here are two attempts to use
quad
in this case.When
gamma
< 1,quad
reports (correctly) that the integral is probably divergent.