我正在尝试集成一个函数,并尝试将该函数与具有常数但无法正常工作的函数相乘

问题描述 投票:0回答:1
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

python numpy scipy integration theory
1个回答
0
投票

好第一个错误,定义了三个常数作为变量的函数。显式计算积分之外的常数:

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)
© www.soinside.com 2019 - 2024. All rights reserved.