简体   繁体   English

Python 指数积分:exp 中遇到溢出

[英]Python Exponential Integration: Overflow encountered in exp

This has probably been asked a million times;这可能已经被问过一百万次了; but i can't figure out the solution for my specific problem.但我无法为我的具体问题找出解决方案。 Here is my code:这是我的代码:

import numpy as np
import matplotlib.pyplot as plt
from sympy import Symbol, integrate, exp, pprint
from scipy import integrate

I am trying to integrate some function that has an exponential in it over and the bounds include some frequency range, (nu = 1e2,1e3/3) and so i should get a list of points out from this integration but i keep encountering this overflow error and im not sure why.我正在尝试集成一些 function,其中有一个指数,并且边界包括一些频率范围,(nu = 1e2,1e3/3),所以我应该从这个集成中得到一个点列表,但我一直遇到这个溢出错误,我不确定为什么。

M = 2e42
M_dot = 4e33
d = 3.1e26
G = 6.67e-8
c = 3e10
h = 6.636e-27
k = 1.38e-16
sigma = 5.67e-5
R_S = (2*G*M/c**2)
nu = np.linspace(1e2,1e3/3)


T_star = (3*G*M*M_dot/(8*np.pi*sigma*((R_S)**3)))
T_d1 = (T_star)*((2*R_S/R_S)**(-3/4))
T_d2 = (T_star)*((1000*R_S/R_S)**(-3/4))

x_in = (h*nu/k*(T_d1))
x_out = (h*nu/k*(T_d2))

my_list = ([])

a = lambda x: (x**(5/3))*(np.exp(x)-1)**(-1)
for x1,x2 in zip(x_out,x_in):
     my_list.append(integrate.quad(a,x1,x2))

Which is giving me: RuntimeWarning: overflow encountered in exp这给了我:RuntimeWarning:exp中遇到的溢出

How can i fix this?我怎样才能解决这个问题?

In spite of the fact that the numbers are very big.尽管数字非常大。 Answering your question.回答你的问题。

You can use the relation (exp( x ) - 1) -1 = 1/(exp( x )-1) = exp(-x)/(1 - exp(-x)), to rewrite a = lambda x: (x**(5/3))*np.exp(-x) / (np.exp(-x)-1) and this gives you zero.您可以使用关系 (exp( x ) - 1) -1 = 1/(exp( x )-1) = exp(-x)/(1 - exp(-x)) 来重写a = lambda x: (x**(5/3))*np.exp(-x) / (np.exp(-x)-1)这给你零。

*Also you are using a highly suspicious R_S/R_S in the formulas for T_d1 and T_d2, c is the light speed? *另外你在T_d1和T_d2的公式中使用了高度可疑的R_S/R_S ,c是光速吗? Should not be 3e8 instead of 3e10?不应该是 3e8 而不是 3e10?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM