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.
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
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.
*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? Should not be 3e8 instead of 3e10?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.