慢速收敛积分的数值积分

发布于 2025-01-09 10:33:09 字数 979 浏览 1 评论 0原文

我基本上对这种类型的数值积分有一个问题:

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:
enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

摇划花蜜的午后 2025-01-16 10:33:09

积分发散的。这可以通过将 func(w) 的渐近行为视为 w 来解释
→ 无穷大。

func(w) 依赖于 w 的部分是商 Eps(w).imag/abs(Eps(w))**2.

w → Infinity 时,Eps(w) 的实部接近 Eps_inf,虚部趋于 0,因此 w→ ∞,abs(Eps(w))**2Eps_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 会收敛。例如

In [65]: gamma = 1.49

In [66]: quad(func, 0, np.inf)
Out[66]: (28.792185960802843, 3.501437717545741e-07)

In [67]: gamma = 1.2

In [68]: quad(func, 0, np.inf)
Out[68]: (87.82367385721193, 4.4632464835103747e-07)

In [69]: gamma = 1.01

In [70]: quad(func, 0, np.inf)
Out[70]: (2274.435541035491, 2.4941527954069898e-06)

,当 gamma 为 1 时,积分发散。在这种情况下,这里有两次使用quad的尝试。

In [71]: gamma = 1.0

In [72]: quad(func, 0, np.inf)
<ipython-input-72-b9978f1fcdcd>:1: IntegrationWarning: The maximum number of subdivisions (50) has been achieved.
  If increasing the limit yields no improvement it is advised to analyze 
  the integrand in order to determine the difficulties.  If the position of a 
  local difficulty can be determined (singularity, discontinuity) one will 
  probably gain from splitting up the interval and calling the integrator 
  on the subranges.  Perhaps a special-purpose integrator should be used.
  quad(func, 0, np.inf)
Out[72]: (882.2704810872806, 188.89503399200746)

In [73]: quad(func, 0, np.inf, limit=100000)
Out[73]: (inf, inf)

gamma< 1,quad(正确地)报告积分可能发散。

In [74]: gamma = 0.98

In [75]: quad(func, 0, np.inf, limit=100000)
<ipython-input-75-005c1a83e644>:1: IntegrationWarning: The integral is probably divergent, or slowly convergent.
  quad(func, 0, np.inf, limit=100000)
Out[75]: (-1202.853690120471, 1.0195566801485256e-05)

The integral is divergent. This can be explained by looking at the asymptotic behavior of func(w) as w
→ ∞.

The part of func(w) that depends on w is the quotient Eps(w).imag/abs(Eps(w))**2.

As w → ∞, the real part of Eps(w) approaches Eps_inf and the imaginary part goes to 0, so as w → ∞, abs(Eps(w))**2Eps_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 of func(w) will converge. For convergence, Eps(w).imag must converge to 0 "fast enough". As w → ∞, Eps(w).imag behaves like D * w**-gamma, where D is a constant that is independent of w. An integral of the form x**p from x0 to ∞ (for some x0 > 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.

In [65]: gamma = 1.49

In [66]: quad(func, 0, np.inf)
Out[66]: (28.792185960802843, 3.501437717545741e-07)

In [67]: gamma = 1.2

In [68]: quad(func, 0, np.inf)
Out[68]: (87.82367385721193, 4.4632464835103747e-07)

In [69]: gamma = 1.01

In [70]: quad(func, 0, np.inf)
Out[70]: (2274.435541035491, 2.4941527954069898e-06)

The integral is divergent when gamma is 1. Here are two attempts to use quad in this case.

In [71]: gamma = 1.0

In [72]: quad(func, 0, np.inf)
<ipython-input-72-b9978f1fcdcd>:1: IntegrationWarning: The maximum number of subdivisions (50) has been achieved.
  If increasing the limit yields no improvement it is advised to analyze 
  the integrand in order to determine the difficulties.  If the position of a 
  local difficulty can be determined (singularity, discontinuity) one will 
  probably gain from splitting up the interval and calling the integrator 
  on the subranges.  Perhaps a special-purpose integrator should be used.
  quad(func, 0, np.inf)
Out[72]: (882.2704810872806, 188.89503399200746)

In [73]: quad(func, 0, np.inf, limit=100000)
Out[73]: (inf, inf)

When gamma < 1, quad reports (correctly) that the integral is probably divergent.

In [74]: gamma = 0.98

In [75]: quad(func, 0, np.inf, limit=100000)
<ipython-input-75-005c1a83e644>:1: IntegrationWarning: The integral is probably divergent, or slowly convergent.
  quad(func, 0, np.inf, limit=100000)
Out[75]: (-1202.853690120471, 1.0195566801485256e-05)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文