对变量和未知数进行积分

quinncasey22

我是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, 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'

我将不胜感激!

RedKnite

据我所知scipy不支持符号集成。对于类似的东西,sympy可能是一个更好的选择。不过,从该积分来看,我不确定它是否可以用封闭形式表示。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章