其中,g是一个常数,\ mu = 0,但是我收到警告,结果与预期的结果不完全相同。
代码如下:
%matplotlib inline
from scipy.integrate import quad
from numpy import arange
from numpy import pi
import matplotlib.pyplot as plt
import numpy as np
###Parameters
ms = 100. ## m
ggX = 2. ## g
def Integrand(E, T, m_dm):
return ((ggX/(2*(np.pi**2)))*E*(E**2-m_dm**2)**(1/2))/(np.exp(E/T)-1)
def Integrate_E(T,m_dm):
'''
Integrate over E given T and ms
'''
return quad(Integrand, m_dm, np.inf, args=(T,m_dm))[0]
TT = np.logspace(-10,15,100)
nn =[Integrate_E(T,ms) for T in (TT)]
plt.loglog(TT, nn)
plt.grid(True)
这是我得到的结果:
/home/vcti/anaconda3/lib/python3.7/site-packages/scipy/integrate/quadpack.py:385: IntegrationWarning: The algorithm does not converge. Roundoff error is detected
in the extrapolation table. It is assumed that the requested tolerance
cannot be achieved, and that the returned result (if full_output = 1) is
the best which can be obtained.
warnings.warn(msg, IntegrationWarning)
/home/vcti/anaconda3/lib/python3.7/site-packages/scipy/integrate/quadpack.py:385: IntegrationWarning: The integral is probably divergent, or slowly convergent.
warnings.warn(msg, IntegrationWarning)
/home/vcti/anaconda3/lib/python3.7/site-packages/scipy/integrate/quadpack.py:385: 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.
warnings.warn(msg, IntegrationWarning)
情节给出:
对于T大于1e4的值,问题就从此开始。在该值之后,它应该几乎保持恒定,但是您可以看到它显示的可怕峰值。 我试图修改epsabs和epsrel,但是没有用。我试图对积分极限进行划分,显然从E = m到1e4可以正常工作,但是当它从E = 1e5积分到无穷远时又会出现问题。
当我打印积分结果时,它给出nn的荒谬值(它可以从5.454320597790705ee + 17到-3085930898.2363224)。我不知道该怎么办预先感谢!
答案 0 :(得分:0)
您自己提供了答案:积分值绝对是巨大的!这里没有epsabs
是有意义的,因此最好将其设置为np.inf
以将其禁用。有了这一点,人们就会得到共鸣
import matplotlib.pyplot as plt
from scipy.integrate import quad
import numpy as np
m = 100
g = 2.0
TT = np.logspace(-1, 15, 100)
nn = [
g
/ (2 * np.pi ** 2)
* quad(
lambda E: E * np.sqrt(E ** 2 - m ** 2) / (np.exp(E / T) - 1),
m,
np.inf,
epsabs=np.inf,
)[0]
for T in TT
]
plt.loglog(TT, nn, "-")
plt.grid()
plt.show()