Reputation: 39
I'm new to integration in Python, so bear with me. The code short, so I will post the whole thing:
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)
What I would like to do here is integrate over x and have python return a numerical value in terms of T. Obviously T is undefined here because T is an unknown for my problem. The above code returns:
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'
I'd appreciate any help!
Upvotes: 3
Views: 374