import math
import numpy as np
from scipy.integrate import quad
def main(k,h,c):
h = 1.054571*10**-34
k = 1.38049*10**-23
c = 2.99792*10**8
pi = 3.14
y = (k**4*T**4)/(4*pi**2*c**2*h**3)
return y
def r(x):
f = (x**3)/(math.exp(x)-1)
return f
S = quad(main,0,np.inf)
eight_m = main*r
S.append(eight_m)
我正在整合的困难,基本上是在打印我对积分的评估。首先,积分是我的函数main(),它只是一个常数。我要整合的其他功能。通过使用四边形,我的积分从0到无穷大。因此,在求值之后,我想将其与main()相乘。截至目前,我遇到一个错误,说缺少2个参数“ h”和“ c”。我不确定如何解决此问题。enter image description here
好第一个错误,定义了三个常数作为变量的函数。显式计算积分之外的常数:
h = 1.054571*10**-34
k = 1.38049*10**-23
c = 2.99792*10**8
pi = math.pi
y = (k**4*T**4)/(4*pi**2*c**2*h**3)
第二个错误,使用math.exp
表示无穷大(提高OverflowError
)。使用np.exp
:
def r(x):
return (x**3)/(np.exp(x)-1)
S = quad(r, 0, np.inf)
第三错误,quad
返回一个元组,如果要列表,请在代码中告诉它:
S = list(S)
S.append(S[0] * y)