Python 变量与未知变量的积分
我对Python的集成还不熟悉,所以请耐心听我说。 代码很短,因此我将发布整个内容:Python 变量与未知变量的积分,python,Python,我对Python的集成还不熟悉,所以请耐心听我说。 代码很短,因此我将发布整个内容: h = 6.626E-34 c = 3.0E8 k = 1.3806E-23 import scipy.integrate from scipy.integrate import quad from math import exp, pi def f(x, T): return 4*pi*h*c**2/(x**5*exp(h*c/(x*k*T))-1) res = quad(f, 0.0, 0000
h = 6.626E-34
c = 3.0E8
k = 1.3806E-23
import scipy.integrate
from scipy.integrate import quad
from math import exp, pi
def f(x, T):
return 4*pi*h*c**2/(x**5*exp(h*c/(x*k*T))-1)
res = quad(f, 0.0, 000000.3)
print(res)
这里我想做的是对x进行积分,让python返回一个关于T的数值。显然,T在这里是未定义的,因为T对于我的问题来说是未知的。上述代码返回:
TypeError Traceback (most recent call last)
<ipython-input-55-4227cf12c600> in <module>
2 return 4*pi*h*c**2/(x**5*exp(h*c/(x*k*T))-1)
3
----> 4 res = quad(f, 0.0, 000000.3)
5 print(res)
~/anaconda3/lib/python3.7/site-packages/scipy/integrate/quadpack.py in quad(func, a, b, args, full_output, epsabs, epsrel, limit, points, weight, wvar, wopts, maxp1, limlst)
340 if weight is None:
341 retval = _quad(func, a, b, args, full_output, epsabs, epsrel, limit,
--> 342 points)
343 else:
344 if points is not None:
~/anaconda3/lib/python3.7/site-packages/scipy/integrate/quadpack.py in _quad(func, a, b, args, full_output, epsabs, epsrel, limit, points)
451 if points is None:
452 if infbounds == 0:
--> 453 return _quadpack._qagse(func,a,b,args,full_output,epsabs,epsrel,limit)
454 else:
455 return _quadpack._qagie(func,bound,infbounds,args,full_output,epsabs,epsrel,limit)
TypeError: f() missing 1 required positional argument: 'T'
TypeError回溯(最近一次调用)
在里面
2返回4*pi*h*c**2/(x**5*exp(h*c/(x*k*T))-1)
3.
---->4res=quad(f,0.0000003)
5印刷品(res)
四元组中的~/anaconda3/lib/python3.7/site-packages/scipy/integrate/quadpack.py(func、a、b、args、full_输出、epsabs、epsrel、limit、points、weight、wvar、wopts、maxp1、limlst)
340如果重量为零:
341 retval=_quad(func、a、b、args、full_输出、epsabs、epsrel、limit、,
-->(342分)
343其他:
344如果点不是无:
~/anaconda3/lib/python3.7/site-packages/scipy/integrate/quadpack.py in_quad(func、a、b、args、full_输出、epsabs、epsrel、limit、points)
451如果点为无:
452如果infbounds==0:
-->453返回四块封装(函数、a、b、参数、全输出、epsabs、epsrel、极限)
454其他:
455返回_quadpack._qagie(func、bound、inbounds、args、full_输出、epsabs、epsrel、limit)
TypeError:f()缺少1个必需的位置参数:“T”
我将感谢任何帮助 据我所知,scipy不支持符号集成。对于这样的事情可能是一个更好的选择。但是,看看这个积分,我不确定它是否可以用封闭形式表示。请提供完整的错误消息。只需编辑帖子并添加完整的错误消息